Tailwind CSS는 마크업에서 직접 디자인을 구축할 수 있는 유틸리티 우선 CSS 프레임워크입니다. 커스텀 CSS를 작성하는 대신 미리 구축된 유틸리티 클래스를 적용합니다. 이 완전한 Tailwind CSS 치트 시트는 모든 주요 카테고리의 클래스와 CSS 출력을 다룹니다.
왜 Tailwind CSS인가? 왜 치트 시트가 필요한가?
Tailwind CSS에는 수백 개의 유틸리티 클래스가 있습니다. 명명 규칙이 직관적이지만, 빠른 참조 시트가 있으면 시간을 절약하고 생산성을 높일 수 있습니다.
간격: 패딩과 마진
Tailwind는 일관된 간격 스케일을 사용합니다. p- 또는 m- 뒤의 숫자는 rem 값에 매핑됩니다(0.25rem 곱하기). 음수 마진은 -m- 접두사를 사용합니다.
| Class | CSS Output | Value |
|---|
p-0 | padding: 0px | 0px |
p-1 | padding: 0.25rem | 4px |
p-2 | padding: 0.5rem | 8px |
p-3 | padding: 0.75rem | 12px |
p-4 | padding: 1rem | 16px |
p-5 | padding: 1.25rem | 20px |
p-6 | padding: 1.5rem | 24px |
p-8 | padding: 2rem | 32px |
p-10 | padding: 2.5rem | 40px |
p-12 | padding: 3rem | 48px |
p-16 | padding: 4rem | 64px |
p-20 | padding: 5rem | 80px |
p-24 | padding: 6rem | 96px |
p-32 | padding: 8rem | 128px |
p-40 | padding: 10rem | 160px |
p-48 | padding: 12rem | 192px |
p-64 | padding: 16rem | 256px |
p-96 | padding: 24rem | 384px |
Directional Padding & Margin
| Prefix | CSS Property | Description |
|---|
p-* | padding | All sides |
px-* | padding-left + padding-right | Horizontal |
py-* | padding-top + padding-bottom | Vertical |
pt-* | padding-top | Top |
pr-* | padding-right | Right |
pb-* | padding-bottom | Bottom |
pl-* | padding-left | Left |
m-* | margin | All sides |
mx-* | margin-left + margin-right | Horizontal |
my-* | margin-top + margin-bottom | Vertical |
-m-4 | margin: -1rem | Negative margin |
m-auto | margin: auto | Auto margin |
<!-- Spacing examples -->
<div class="p-4">padding 1rem all sides</div>
<div class="px-6 py-3">horizontal 1.5rem, vertical 0.75rem</div>
<div class="mt-8 mb-4">top margin 2rem, bottom margin 1rem</div>
<div class="mx-auto max-w-lg">centered container</div>
<div class="-mt-4">negative top margin (overlap)</div>
<div class="space-x-4">children spaced 1rem horizontally</div>
<div class="space-y-2">children spaced 0.5rem vertically</div>
타이포그래피
글꼴 크기, 굵기, 줄 높이, 자간, 텍스트 정렬, 텍스트 색상 유틸리티.
글꼴 크기
| Class | CSS Output | Size |
|---|
text-xs | font-size: 0.75rem; line-height: 1rem | 12px |
text-sm | font-size: 0.875rem; line-height: 1.25rem | 14px |
text-base | font-size: 1rem; line-height: 1.5rem | 16px |
text-lg | font-size: 1.125rem; line-height: 1.75rem | 18px |
text-xl | font-size: 1.25rem; line-height: 1.75rem | 20px |
text-2xl | font-size: 1.5rem; line-height: 2rem | 24px |
text-3xl | font-size: 1.875rem; line-height: 2.25rem | 30px |
text-4xl | font-size: 2.25rem; line-height: 2.5rem | 36px |
text-5xl | font-size: 3rem; line-height: 1 | 48px |
text-6xl | font-size: 3.75rem; line-height: 1 | 60px |
text-7xl | font-size: 4.5rem; line-height: 1 | 72px |
text-8xl | font-size: 6rem; line-height: 1 | 96px |
text-9xl | font-size: 8rem; line-height: 1 | 128px |
글꼴 굵기
| Class | CSS Output |
|---|
font-thin | font-weight: 100 |
font-extralight | font-weight: 200 |
font-light | font-weight: 300 |
font-normal | font-weight: 400 |
font-medium | font-weight: 500 |
font-semibold | font-weight: 600 |
font-bold | font-weight: 700 |
font-extrabold | font-weight: 800 |
font-black | font-weight: 900 |
줄 높이
| Class | CSS Output |
|---|
leading-none | line-height: 1 |
leading-tight | line-height: 1.25 |
leading-snug | line-height: 1.375 |
leading-normal | line-height: 1.5 |
leading-relaxed | line-height: 1.625 |
leading-loose | line-height: 2 |
leading-3 | line-height: 0.75rem |
leading-6 | line-height: 1.5rem |
leading-8 | line-height: 2rem |
leading-10 | line-height: 2.5rem |
자간
| Class | CSS Output |
|---|
tracking-tighter | letter-spacing: -0.05em |
tracking-tight | letter-spacing: -0.025em |
tracking-normal | letter-spacing: 0em |
tracking-wide | letter-spacing: 0.025em |
tracking-wider | letter-spacing: 0.05em |
tracking-widest | letter-spacing: 0.1em |
텍스트 정렬
| Class | CSS Output |
|---|
text-left | text-align: left |
text-center | text-align: center |
text-right | text-align: right |
text-justify | text-align: justify |
text-start | text-align: start |
text-end | text-align: end |
텍스트 색상
<!-- Text color examples -->
<p class="text-black">text-black → color: #000</p>
<p class="text-white">text-white → color: #fff</p>
<p class="text-gray-500">text-gray-500 → color: #6b7280</p>
<p class="text-red-600">text-red-600 → color: #dc2626</p>
<p class="text-blue-500">text-blue-500 → color: #3b82f6</p>
<p class="text-green-700">text-green-700 → color: #15803d</p>
<p class="text-transparent">text-transparent → color: transparent</p>
<p class="text-current">text-current → color: currentColor</p>
색상
Tailwind는 50(가장 밝음)에서 950(가장 어두움)까지의 숫자 색상 스케일을 사용합니다. 접두사: bg-는 배경, text-는 텍스트, border-는 테두리.
| Shade | bg-blue-* | Hex Value | Usage |
|---|
50 | bg-blue-50 | #eff6ff | Lightest background |
100 | bg-blue-100 | #dbeafe | Light background |
200 | bg-blue-200 | #bfdbfe | Hover states, light borders |
300 | bg-blue-300 | #93c5fd | Active states |
400 | bg-blue-400 | #60a5fa | Icons, secondary elements |
500 | bg-blue-500 | #3b82f6 | Primary brand color |
600 | bg-blue-600 | #2563eb | Primary buttons, links |
700 | bg-blue-700 | #1d4ed8 | Hover on primary |
800 | bg-blue-800 | #1e40af | Dark accents |
900 | bg-blue-900 | #1e3a8a | Darkest accent |
950 | bg-blue-950 | #172554 | Near-black backgrounds |
Color Prefixes
| Prefix | CSS Property | Example |
|---|
bg-* | background-color | bg-red-500 |
text-* | color | text-blue-600 |
border-* | border-color | border-gray-300 |
ring-* | box-shadow (ring) | ring-indigo-500 |
divide-* | border-color (dividers) | divide-gray-200 |
placeholder-* | placeholder color | placeholder-gray-400 |
from-* | gradient start | from-purple-500 |
via-* | gradient middle | via-pink-500 |
to-* | gradient end | to-red-500 |
<!-- Available color palettes -->
slate, gray, zinc, neutral, stone <!-- Grays -->
red, orange, amber, yellow <!-- Warm -->
lime, green, emerald, teal <!-- Green -->
cyan, sky, blue, indigo <!-- Blue -->
violet, purple, fuchsia, pink, rose <!-- Purple/Pink -->
<!-- Gradient example -->
<div class="bg-gradient-to-r from-blue-500 via-purple-500 to-pink-500">
Gradient background
</div>
Flexbox
유연한 레이아웃을 구축하기 위한 포괄적인 flexbox 유틸리티.
| Class | CSS Output |
|---|
flex | display: flex |
inline-flex | display: inline-flex |
flex-row | flex-direction: row |
flex-row-reverse | flex-direction: row-reverse |
flex-col | flex-direction: column |
flex-col-reverse | flex-direction: column-reverse |
flex-wrap | flex-wrap: wrap |
flex-wrap-reverse | flex-wrap: wrap-reverse |
flex-nowrap | flex-wrap: nowrap |
flex-1 | flex: 1 1 0% |
flex-auto | flex: 1 1 auto |
flex-initial | flex: 0 1 auto |
flex-none | flex: none |
Justify & Align
| Class | CSS Output |
|---|
justify-start | justify-content: flex-start |
justify-end | justify-content: flex-end |
justify-center | justify-content: center |
justify-between | justify-content: space-between |
justify-around | justify-content: space-around |
justify-evenly | justify-content: space-evenly |
items-start | align-items: flex-start |
items-end | align-items: flex-end |
items-center | align-items: center |
items-baseline | align-items: baseline |
items-stretch | align-items: stretch |
Gap
| Class | CSS Output |
|---|
gap-0 | gap: 0px |
gap-1 | gap: 0.25rem (4px) |
gap-2 | gap: 0.5rem (8px) |
gap-4 | gap: 1rem (16px) |
gap-6 | gap: 1.5rem (24px) |
gap-8 | gap: 2rem (32px) |
gap-x-4 | column-gap: 1rem |
gap-y-4 | row-gap: 1rem |
<!-- Flexbox layout examples -->
<!-- Centered content -->
<div class="flex items-center justify-center h-screen">
<div>Perfectly centered</div>
</div>
<!-- Navbar: logo left, links right -->
<nav class="flex justify-between items-center p-4">
<div class="text-xl font-bold">Logo</div>
<div class="flex gap-4">
<a href="#">Home</a>
<a href="#">About</a>
<a href="#">Contact</a>
</div>
</nav>
<!-- Responsive cards -->
<div class="flex flex-wrap gap-4">
<div class="flex-1 min-w-[300px]">Card 1</div>
<div class="flex-1 min-w-[300px]">Card 2</div>
<div class="flex-1 min-w-[300px]">Card 3</div>
</div>
Grid
2차원 레이아웃을 만들기 위한 CSS Grid 유틸리티.
| Class | CSS Output |
|---|
grid | display: grid |
grid-cols-1 | grid-template-columns: repeat(1, minmax(0, 1fr)) |
grid-cols-2 | grid-template-columns: repeat(2, minmax(0, 1fr)) |
grid-cols-3 | grid-template-columns: repeat(3, minmax(0, 1fr)) |
grid-cols-4 | grid-template-columns: repeat(4, minmax(0, 1fr)) |
grid-cols-6 | grid-template-columns: repeat(6, minmax(0, 1fr)) |
grid-cols-12 | grid-template-columns: repeat(12, minmax(0, 1fr)) |
grid-cols-none | grid-template-columns: none |
grid-rows-1 | grid-template-rows: repeat(1, minmax(0, 1fr)) |
grid-rows-3 | grid-template-rows: repeat(3, minmax(0, 1fr)) |
grid-rows-6 | grid-template-rows: repeat(6, minmax(0, 1fr)) |
Column & Row Span
| Class | CSS Output |
|---|
col-span-1 | grid-column: span 1 / span 1 |
col-span-2 | grid-column: span 2 / span 2 |
col-span-3 | grid-column: span 3 / span 3 |
col-span-4 | grid-column: span 4 / span 4 |
col-span-6 | grid-column: span 6 / span 6 |
col-span-full | grid-column: 1 / -1 |
row-span-1 | grid-row: span 1 / span 1 |
row-span-2 | grid-row: span 2 / span 2 |
row-span-3 | grid-row: span 3 / span 3 |
row-span-full | grid-row: 1 / -1 |
auto-cols-auto | grid-auto-columns: auto |
auto-cols-fr | grid-auto-columns: minmax(0, 1fr) |
auto-rows-auto | grid-auto-rows: auto |
auto-rows-fr | grid-auto-rows: minmax(0, 1fr) |
<!-- Grid layout examples -->
<!-- 3-column grid -->
<div class="grid grid-cols-3 gap-4">
<div>1</div> <div>2</div> <div>3</div>
<div>4</div> <div>5</div> <div>6</div>
</div>
<!-- Responsive grid: 1 col mobile, 2 tablet, 3 desktop -->
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
<div>Card 1</div>
<div>Card 2</div>
<div>Card 3</div>
</div>
<!-- Dashboard layout with spanning -->
<div class="grid grid-cols-4 gap-4">
<div class="col-span-4">Header (full width)</div>
<div class="col-span-1">Sidebar</div>
<div class="col-span-3">Main content</div>
<div class="col-span-2">Half width</div>
<div class="col-span-2">Half width</div>
</div>
레이아웃: 너비, 높이, 컨테이너
요소 크기와 레이아웃 컨테이너를 제어하는 유틸리티.
| Class | CSS Output |
|---|
w-0 | width: 0px |
w-1 | width: 0.25rem (4px) |
w-4 | width: 1rem (16px) |
w-8 | width: 2rem (32px) |
w-16 | width: 4rem (64px) |
w-32 | width: 8rem (128px) |
w-64 | width: 16rem (256px) |
w-1/2 | width: 50% |
w-1/3 | width: 33.333% |
w-2/3 | width: 66.667% |
w-1/4 | width: 25% |
w-3/4 | width: 75% |
w-full | width: 100% |
w-screen | width: 100vw |
w-auto | width: auto |
w-fit | width: fit-content |
w-min | width: min-content |
w-max | width: max-content |
Height & Max/Min
| Class | CSS Output |
|---|
h-0 | height: 0px |
h-4 | height: 1rem (16px) |
h-16 | height: 4rem (64px) |
h-64 | height: 16rem (256px) |
h-full | height: 100% |
h-screen | height: 100vh |
h-auto | height: auto |
min-h-0 | min-height: 0px |
min-h-full | min-height: 100% |
min-h-screen | min-height: 100vh |
max-w-sm | max-width: 24rem (384px) |
max-w-md | max-width: 28rem (448px) |
max-w-lg | max-width: 32rem (512px) |
max-w-xl | max-width: 36rem (576px) |
max-w-2xl | max-width: 42rem (672px) |
max-w-4xl | max-width: 56rem (896px) |
max-w-6xl | max-width: 72rem (1152px) |
max-w-7xl | max-width: 80rem (1280px) |
max-w-full | max-width: 100% |
max-w-none | max-width: none |
container | width: 100% (responsive max-width) |
<!-- Layout examples -->
<div class="container mx-auto px-4">
Centered responsive container
</div>
<div class="max-w-2xl mx-auto">
Max-width 672px, centered
</div>
<div class="w-full h-screen">
Full width, full viewport height
</div>
<div class="min-h-screen flex flex-col">
<main class="flex-1">Content</main>
<footer>Footer always at bottom</footer>
</div>
테두리와 모서리 둥글기
테두리 너비, 스타일, 둥근 모서리, 링 효과 유틸리티.
| Class | CSS Output |
|---|
border | border-width: 1px |
border-0 | border-width: 0px |
border-2 | border-width: 2px |
border-4 | border-width: 4px |
border-8 | border-width: 8px |
border-t | border-top-width: 1px |
border-r-2 | border-right-width: 2px |
border-b-4 | border-bottom-width: 4px |
border-l | border-left-width: 1px |
border-solid | border-style: solid |
border-dashed | border-style: dashed |
border-dotted | border-style: dotted |
border-none | border-style: none |
Border Radius
| Class | CSS Output |
|---|
rounded-none | border-radius: 0px |
rounded-sm | border-radius: 0.125rem (2px) |
rounded | border-radius: 0.25rem (4px) |
rounded-md | border-radius: 0.375rem (6px) |
rounded-lg | border-radius: 0.5rem (8px) |
rounded-xl | border-radius: 0.75rem (12px) |
rounded-2xl | border-radius: 1rem (16px) |
rounded-3xl | border-radius: 1.5rem (24px) |
rounded-full | border-radius: 9999px |
rounded-t-lg | border-top-left/right-radius: 0.5rem |
rounded-b-lg | border-bottom-left/right-radius: 0.5rem |
Ring (Outline)
| Class | CSS Output |
|---|
ring-0 | box-shadow: 0 0 0 0px ... |
ring-1 | box-shadow: 0 0 0 1px ... |
ring-2 | box-shadow: 0 0 0 2px ... |
ring-4 | box-shadow: 0 0 0 4px ... |
ring | box-shadow: 0 0 0 3px ... |
ring-inset | box-shadow: inset ... |
ring-blue-500 | ring color: #3b82f6 |
ring-offset-2 | ring offset: 2px |
ring-offset-white | ring offset color: #fff |
그림자와 효과
박스 그림자, 불투명도, 블러 효과 유틸리티.
| Class | CSS Output |
|---|
shadow-sm | box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05) |
shadow | box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1) |
shadow-md | box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1) |
shadow-lg | box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1) |
shadow-xl | box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1) |
shadow-2xl | box-shadow: 0 25px 50px -12px rgb(0 0 0 / 0.25) |
shadow-inner | box-shadow: inset 0 2px 4px 0 rgb(0 0 0 / 0.05) |
shadow-none | box-shadow: 0 0 #0000 |
Opacity & Blur
| Class | CSS Output |
|---|
opacity-0 | opacity: 0 |
opacity-25 | opacity: 0.25 |
opacity-50 | opacity: 0.5 |
opacity-75 | opacity: 0.75 |
opacity-100 | opacity: 1 |
blur-none | filter: blur(0) |
blur-sm | filter: blur(4px) |
blur | filter: blur(8px) |
blur-md | filter: blur(12px) |
blur-lg | filter: blur(16px) |
blur-xl | filter: blur(24px) |
blur-2xl | filter: blur(40px) |
blur-3xl | filter: blur(64px) |
backdrop-blur-sm | backdrop-filter: blur(4px) |
backdrop-blur | backdrop-filter: blur(8px) |
backdrop-blur-md | backdrop-filter: blur(12px) |
backdrop-blur-lg | backdrop-filter: blur(16px) |
backdrop-blur-xl | backdrop-filter: blur(24px) |
트랜지션과 애니메이션
CSS 트랜지션과 키프레임 애니메이션 유틸리티.
| Class | CSS Output |
|---|
transition-none | transition-property: none |
transition-all | transition-property: all |
transition | transition-property: color, background-color, border-color, text-decoration-color, fill, stroke, opacity, box-shadow, transform, filter, backdrop-filter |
transition-colors | transition-property: color, background-color, border-color, text-decoration-color, fill, stroke |
transition-opacity | transition-property: opacity |
transition-shadow | transition-property: box-shadow |
transition-transform | transition-property: transform |
Duration & Easing
| Class | CSS Output |
|---|
duration-75 | transition-duration: 75ms |
duration-100 | transition-duration: 100ms |
duration-150 | transition-duration: 150ms |
duration-200 | transition-duration: 200ms |
duration-300 | transition-duration: 300ms |
duration-500 | transition-duration: 500ms |
duration-700 | transition-duration: 700ms |
duration-1000 | transition-duration: 1000ms |
ease-linear | transition-timing-function: linear |
ease-in | transition-timing-function: cubic-bezier(0.4, 0, 1, 1) |
ease-out | transition-timing-function: cubic-bezier(0, 0, 0.2, 1) |
ease-in-out | transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1) |
Animations
| Class | Description |
|---|
animate-none | No animation |
animate-spin | Continuous rotation (loading spinners) |
animate-ping | Scale + fade out (notification dot) |
animate-pulse | Gentle fade in/out (skeleton loaders) |
animate-bounce | Bouncing motion (scroll indicator) |
<!-- Transition examples -->
<button class="bg-blue-500 hover:bg-blue-700 transition-colors duration-200">
Smooth color change on hover
</button>
<div class="hover:scale-105 transition-transform duration-300 ease-out">
Scale up on hover
</div>
<div class="hover:shadow-xl transition-shadow duration-300">
Shadow appears on hover
</div>
<!-- Animation examples -->
<svg class="animate-spin h-5 w-5">...</svg> <!-- Loading spinner -->
<span class="animate-ping absolute">...</span> <!-- Notification dot -->
<div class="animate-pulse bg-gray-300 h-4 rounded">...</div> <!-- Skeleton -->
반응형 접두사
Tailwind는 모바일 우선 반응형 디자인을 사용합니다. 유틸리티에 브레이크포인트 접두사를 붙여 적용합니다.
| Prefix | Min Width | CSS Media Query |
|---|
(none) | 0px | No media query (applies to all) |
sm: | 640px | @media (min-width: 640px) { ... } |
md: | 768px | @media (min-width: 768px) { ... } |
lg: | 1024px | @media (min-width: 1024px) { ... } |
xl: | 1280px | @media (min-width: 1280px) { ... } |
2xl: | 1536px | @media (min-width: 1536px) { ... } |
<!-- Mobile-first responsive design -->
<!-- Stack on mobile, side-by-side on tablet+ -->
<div class="flex flex-col md:flex-row gap-4">
<div class="w-full md:w-1/3">Sidebar</div>
<div class="w-full md:w-2/3">Main</div>
</div>
<!-- Responsive text size -->
<h1 class="text-2xl sm:text-3xl md:text-4xl lg:text-5xl">
Responsive Heading
</h1>
<!-- Responsive grid columns -->
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6">
<div>Card</div>
<div>Card</div>
<div>Card</div>
<div>Card</div>
</div>
<!-- Hide/show at breakpoints -->
<div class="hidden md:block">Visible on md and above</div>
<div class="block md:hidden">Visible only below md</div>
<!-- Responsive padding -->
<div class="p-4 sm:p-6 md:p-8 lg:p-12">
Padding grows with screen size
</div>
상태 변형
상태 변형 접두사를 사용하여 조건부로 스타일을 적용합니다.
| Variant | CSS Selector / Condition | Example |
|---|
hover: | :hover | hover:bg-blue-700 |
focus: | :focus | focus:outline-none focus:ring-2 |
focus-within: | :focus-within | focus-within:border-blue-500 |
focus-visible: | :focus-visible | focus-visible:ring-2 |
active: | :active | active:bg-blue-800 |
disabled: | :disabled | disabled:opacity-50 |
visited: | :visited | visited:text-purple-600 |
first: | :first-child | first:mt-0 |
last: | :last-child | last:mb-0 |
odd: | :nth-child(odd) | odd:bg-gray-100 |
even: | :nth-child(even) | even:bg-gray-50 |
group-hover: | .group:hover & | group-hover:text-white |
peer-focus: | .peer:focus ~ & | peer-focus:text-blue-500 |
dark: | prefers-color-scheme: dark | dark:bg-gray-900 |
placeholder: | ::placeholder | placeholder:text-gray-400 |
before: | ::before | before:content-[""] |
after: | ::after | after:content-[""] |
<!-- State variant examples -->
<!-- Button with multiple states -->
<button class="bg-blue-500 hover:bg-blue-700 active:bg-blue-800
focus:outline-none focus:ring-2 focus:ring-blue-300
disabled:opacity-50 disabled:cursor-not-allowed
transition-colors duration-200">
Click me
</button>
<!-- Group hover: parent hover affects child -->
<div class="group p-4 hover:bg-blue-50 rounded-lg">
<h3 class="group-hover:text-blue-600">Title</h3>
<p class="group-hover:text-blue-400">Description</p>
</div>
<!-- Dark mode -->
<div class="bg-white dark:bg-gray-900 text-black dark:text-white">
Adapts to light/dark mode
</div>
<!-- Peer: input state affects sibling -->
<input class="peer" type="text" placeholder="Email" />
<p class="invisible peer-invalid:visible text-red-500">
Invalid email address
</p>
팁과 고급 사용법
내장 유틸리티로 충분하지 않을 때의 고급 기능.
임의 값
대괄호를 사용하여 커스텀 값 지정:
<!-- Arbitrary values with square brackets -->
<div class="w-[120px]">width: 120px</div>
<div class="h-[calc(100vh-80px)]">height: calc(100vh - 80px)</div>
<div class="bg-[#1a2b3c]">background: #1a2b3c</div>
<div class="text-[22px]">font-size: 22px</div>
<div class="grid-cols-[200px_1fr_200px]">custom grid template</div>
<div class="p-[clamp(1rem,3vw,3rem)]">responsive clamp padding</div>
<div class="text-[color:var(--brand)]">CSS variable color</div>
<div class="top-[var(--header-h)]">CSS variable position</div>
Important 수정자
유틸리티 앞에 !를 붙여 !important 추가:
<!-- Important modifier with ! prefix -->
<div class="!p-4">padding: 1rem !important</div>
<div class="!mt-0">margin-top: 0 !important</div>
<div class="!text-red-500">color: #ef4444 !important</div>
<!-- Useful for overriding third-party styles -->
<div class="external-widget !bg-transparent !border-none">
Override library styles
</div>
@apply 지시어
반복되는 유틸리티 패턴을 커스텀 CSS 클래스로 추출:
/* In your CSS file — use @apply to extract components */
.btn {
@apply px-4 py-2 rounded-lg font-semibold transition-colors duration-200;
}
.btn-primary {
@apply btn bg-blue-500 text-white hover:bg-blue-700;
}
.btn-secondary {
@apply btn bg-gray-200 text-gray-800 hover:bg-gray-300;
}
.input {
@apply w-full px-3 py-2 border border-gray-300 rounded-md
focus:outline-none focus:ring-2 focus:ring-blue-500
focus:border-transparent;
}
.card {
@apply bg-white dark:bg-gray-800 rounded-xl shadow-md p-6
hover:shadow-lg transition-shadow duration-300;
}
/* Note: Tailwind recommends using utilities directly in HTML
and only extracting with @apply for truly repeated patterns. */
자주 묻는 질문
Tailwind CSS와 일반 CSS의 차이점은 무엇인가요?
Tailwind CSS는 HTML에 직접 적용하는 미리 구축된 CSS 클래스를 제공하는 유틸리티 우선 프레임워크입니다. p-4, text-lg, bg-blue-500 같은 클래스명으로 요소를 스타일링합니다.
Tailwind CSS 간격 스케일은 어떻게 작동하나요?
각 단위는 0.25rem(4px)입니다. p-1은 0.25rem, p-4는 1rem(16px)입니다. 스케일은 0에서 96(24rem/384px)까지이며 p-[13px] 같은 임의 값도 사용 가능합니다.
반응형 브레이크포인트는 어떻게 작동하나요?
모바일 우선 접근 방식입니다. 접두사 없는 유틸리티는 모든 화면에 적용됩니다. md:flex 같은 접두사는 해당 브레이크포인트 이상에서 적용됩니다. 기본값: sm(640px), md(768px), lg(1024px), xl(1280px), 2xl(1536px).
커스텀 색상을 사용할 수 있나요?
네. tailwind.config.js의 theme.extend.colors에서 확장하거나 bg-[#1a2b3c] 같은 임의 값을 직접 사용할 수 있습니다.
@apply 지시어란 무엇인가요?
@apply는 반복되는 유틸리티 패턴을 커스텀 CSS 클래스로 추출합니다. 여러 버튼에서 같은 클래스 조합을 사용할 때 유용하지만 절제하여 사용하세요.
다크 모드를 지원하려면 어떻게 하나요?
dark: 변형을 사용합니다. bg-white dark:bg-gray-900처럼 유틸리티에 dark: 접두사를 붙입니다. tailwind.config.js에서 "media" 또는 "class" 전략을 설정합니다.