Tailwind CSS is a utility-first CSS framework that lets you build designs directly in your markup. Instead of writing custom CSS, you apply pre-built utility classes. This complete Tailwind CSS cheat sheet covers every major category of classes with their CSS output, so you can quickly look up any utility you need.
Why Tailwind CSS and Why a Cheat Sheet?
Tailwind CSS has hundreds of utility classes. While the naming convention is intuitive, having a quick-reference cheat sheet saves time and boosts productivity. This guide organizes all essential classes by category with exact CSS output.
Spacing: Padding & Margin
Tailwind uses a consistent spacing scale. The number after p- or m- maps to a rem value (multiply by 0.25rem). Negative margins use -m- prefix.
| 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>
Typography
Tailwind provides utilities for font size, weight, line height, letter spacing, text alignment, and text color.
Font Size
| 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 |
Font Weight
| 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 |
Line Height
| 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 |
Letter Spacing
| 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 |
Text Alignment
| 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
<!-- 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>
Colors
Tailwind uses a numeric color scale from 50 (lightest) to 950 (darkest). Colors are applied with prefixes: bg- for background, text- for text, and border- for borders.
| 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
Tailwind provides comprehensive flexbox utilities for building flexible layouts.
| 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
CSS Grid utilities for creating two-dimensional layouts.
| 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>
Layout: Width, Height & Container
Utilities for controlling element dimensions and layout containers.
| 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>
Borders & Rounded Corners
Utilities for border width, style, radius, and ring (outline) effects.
| 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 |
Shadows & Effects
Utilities for box shadows, opacity, and blur effects.
| 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) |
Transitions & Animation
Utilities for CSS transitions and keyframe animations.
| 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 -->
Responsive Prefixes
Tailwind uses mobile-first responsive design. Prefix any utility with a breakpoint to apply it at that screen size and above.
| 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>
State Variants
Apply styles conditionally using state variant prefixes.
| 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>
Tips & Advanced Usage
Power-user features for when the built-in utilities are not enough.
Arbitrary Values
Use square brackets to specify any custom value:
<!-- 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 Modifier
Prefix any utility with ! to add !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 Directive
Extract repeated utility patterns into custom CSS classes:
/* 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. */
Frequently Asked Questions
What is the difference between Tailwind CSS and regular CSS?
Tailwind CSS is a utility-first framework that provides pre-built CSS classes you apply directly in HTML. Unlike regular CSS where you write custom stylesheets, Tailwind lets you style elements inline using class names like p-4, text-lg, and bg-blue-500. This approach eliminates the need to switch between HTML and CSS files and avoids naming CSS classes.
How does the Tailwind CSS spacing scale work?
Tailwind uses a consistent spacing scale where each unit equals 0.25rem (4px). So p-1 is 0.25rem (4px), p-2 is 0.5rem (8px), p-4 is 1rem (16px), and so on. The scale goes from 0 to 96 (24rem/384px). You can also use arbitrary values like p-[13px] for custom spacing.
How do responsive breakpoints work in Tailwind CSS?
Tailwind uses a mobile-first approach. Unprefixed utilities apply to all screen sizes. Prefixed utilities like md:flex only apply at that breakpoint and above. The default breakpoints are sm (640px), md (768px), lg (1024px), xl (1280px), and 2xl (1536px). You stack prefixes to create responsive designs, e.g., w-full md:w-1/2 lg:w-1/3.
Can I use custom colors in Tailwind CSS?
Yes. You can extend the default color palette in tailwind.config.js under theme.extend.colors. You can also use arbitrary values like bg-[#1a2b3c] or text-[rgb(255,100,50)] directly in your markup for one-off colors without modifying the config.
What is the @apply directive and when should I use it?
The @apply directive lets you extract repeated utility patterns into custom CSS classes. For example, if you use "px-4 py-2 bg-blue-500 text-white rounded" on many buttons, you can create a .btn class with @apply. Use it sparingly - Tailwind recommends using utilities directly and only extracting components when you have true duplication across many files.
How do I make Tailwind CSS work with dark mode?
Tailwind supports dark mode via the dark: variant. Prefix any utility with dark: to apply it when dark mode is active, e.g., bg-white dark:bg-gray-900. Configure dark mode strategy in tailwind.config.js as "media" (follows OS preference) or "class" (toggle via a class on the html element).