Tailwind CSS
Comprehensive Tailwind CSS v4 reference covering utility classes, dark mode, states, responsive design, colors, layout, typography, customization with @theme, and more.
Sign in to mark items as known and track your progress.
Sign inInstallation & Setup
Install Tailwind CSS v4 and configure your project.
Installation (v4)
Install Tailwind CSS v4 with Vite, PostCSS, or the CLI.
/* CDN (quickest way to try it) */
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>
/* Install with Vite (recommended for projects) */
npm install tailwindcss @tailwindcss/vite
/* vite.config.ts */
import tailwindcss from "@tailwindcss/vite"
export default { plugins: [tailwindcss()] }
/* app.css - single import, no config file needed */
@import "tailwindcss";Dark Mode
Style for light and dark color schemes using the dark: variant.
Dark Mode
Apply different styles in dark mode using the dark: variant.
<!-- Follows system preference by default -->
<div class="bg-white dark:bg-gray-900">
<h1 class="text-gray-900 dark:text-white">Title</h1>
<p class="text-gray-600 dark:text-gray-300">Text</p>
</div>States & Variants
Apply styles on hover, focus, active, and other interactive states.
Hover, Focus & Other States
Style elements based on pseudo-classes and interactive states.
<!-- Hover & focus -->
<button class="bg-blue-500 hover:bg-blue-600
focus:outline-none focus:ring-2 focus:ring-blue-400">
Button
</button>
<!-- Active, disabled, first/last child -->
<button class="active:scale-95 disabled:opacity-50">
Submit
</button>
<li class="first:pt-0 last:pb-0">Item</li>Group & Peer Modifiers
Style elements based on parent or sibling state.
<!-- Group — style children when parent is hovered -->
<div class="group rounded-lg p-4 hover:bg-gray-100">
<h3 class="group-hover:text-blue-600">Title</h3>
<p class="group-hover:text-gray-700">Description</p>
</div>
<!-- Peer — style based on sibling state -->
<input class="peer" type="checkbox" />
<span class="peer-checked:text-green-500">Enabled</span>Colors & Opacity
Use the color palette and opacity modifiers across all utilities.
Color System & Opacity
Apply colors with the built-in palette and opacity shorthand.
<!-- Colors use shade-50 to shade-950 -->
<p class="text-blue-500">Blue text</p>
<div class="bg-gray-100 border-gray-300">Box</div>
<!-- Opacity modifier — append /opacity -->
<div class="bg-blue-500/75">75% opacity blue</div>
<div class="bg-black/50">50% opacity black</div>
<div class="text-white/80">80% opacity white</div>Layout
Container, display, positioning, z-index, overflow, and columns.
Container & Display
Set container width, display type, and visibility.
<!-- Container — centers and max-widths content -->
<div class="container mx-auto px-4">...</div>
<!-- Display -->
<div class="block">Block</div>
<span class="inline-block">Inline block</span>
<div class="hidden">Hidden</div>
<div class="flex">Flex container</div>
<div class="grid">Grid container</div>Positioning & Z-Index
Position elements and control stacking order.
<!-- Position -->
<div class="relative">
<div class="absolute top-0 right-0">Badge</div>
</div>
<nav class="fixed top-0 w-full">Navbar</nav>
<nav class="sticky top-0">Sticky nav</nav>
<!-- Inset & z-index -->
<div class="inset-0">Full overlay</div>
<div class="z-10">Above</div>
<div class="z-50">Topmost</div>Flexbox & Grid
Layout with flexbox and CSS grid utilities.
Flexbox
Flexible box layout for rows and columns.
<!-- Basic flex row -->
<div class="flex gap-4">
<div>Item 1</div>
<div>Item 2</div>
</div>
<!-- Centered content -->
<div class="flex items-center justify-center h-screen">
<p>Perfectly centered</p>
</div>
<!-- Column layout -->
<div class="flex flex-col gap-2">
<div>Top</div>
<div>Bottom</div>
</div>Grid
CSS Grid layout for complex two-dimensional layouts.
<!-- Basic grid -->
<div class="grid grid-cols-3 gap-4">
<div>1</div> <div>2</div> <div>3</div>
</div>
<!-- Responsive grid -->
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
<div>Card</div>
</div>Spacing & Sizing
Padding, margin, width, height, and space between elements.
Padding & Margin
Control inner and outer spacing.
<!-- Padding (all sides, x, y, individual) -->
<div class="p-4">All sides</div>
<div class="px-4 py-2">Horizontal + vertical</div>
<div class="pt-8 pb-4">Top + bottom</div>
<!-- Margin -->
<div class="m-4">All sides</div>
<div class="mx-auto">Center horizontally</div>
<div class="mt-8 mb-4">Top + bottom</div>
<div class="-mt-4">Negative margin</div>Width, Height & Aspect Ratio
Set element dimensions and aspect ratios.
<!-- Width -->
<div class="w-full">100%</div>
<div class="w-1/2">50%</div>
<div class="w-64">16rem (256px)</div>
<div class="max-w-lg">Max width large</div>
<div class="min-w-0">Min width zero</div>
<!-- Height -->
<div class="h-screen">Full viewport</div>
<div class="h-full">Full parent</div>
<div class="min-h-screen">At least full viewport</div>Typography
Font sizing, weight, text color, decoration, alignment, and line clamp.
Font & Text
Control font size, weight, line height, and text styling.
<!-- Font size -->
<p class="text-sm">Small</p>
<p class="text-base">Base (1rem)</p>
<p class="text-xl">Extra large</p>
<p class="text-4xl font-bold">Heading</p>
<!-- Text color & decoration -->
<p class="text-gray-600">Gray text</p>
<a class="underline decoration-blue-500">Link</a>
<p class="line-through">Deleted</p>Text Alignment & Wrapping
Align text and control overflow behavior.
<!-- Alignment -->
<p class="text-left">Left aligned</p>
<p class="text-center">Centered</p>
<p class="text-right">Right aligned</p>
<!-- Wrapping & overflow -->
<p class="truncate">Truncate with ellipsis...</p>
<p class="text-wrap">Normal wrapping</p>
<p class="text-nowrap">No wrapping</p>
<p class="text-balance">Balanced line breaks</p>
<p class="break-words">Break long words</p>Backgrounds & Borders
Background colors, gradients, border radius, rings, and outlines.
Backgrounds & Gradients
Background colors, images, and gradient utilities.
<!-- Background color -->
<div class="bg-white dark:bg-gray-900">Card</div>
<div class="bg-blue-500/10">Subtle tint</div>
<!-- Gradients -->
<div class="bg-gradient-to-r from-blue-500 to-purple-500">
Left to right gradient
</div>
<div class="bg-gradient-to-br from-pink-500 via-red-500 to-yellow-500">
Three-color diagonal gradient
</div>Borders, Rings & Radius
Border styling, focus rings, outlines, and rounded corners.
<!-- Border -->
<div class="border border-gray-300">Default border</div>
<div class="border-2 border-blue-500">Thick colored</div>
<div class="border-b border-gray-200">Bottom only</div>
<!-- Rounded corners -->
<div class="rounded">Small radius</div>
<div class="rounded-lg">Large radius</div>
<div class="rounded-full">Pill/circle</div>
<!-- Ring (focus indicator) -->
<button class="ring-2 ring-blue-500">Ring</button>
<input class="focus:ring-2 focus:ring-blue-500" />Effects & Filters
Shadows, opacity, blend modes, and CSS filters.
Shadows, Opacity & Filters
Box shadows, opacity, and visual filters.
<!-- Box shadows -->
<div class="shadow-sm">Small shadow</div>
<div class="shadow-lg">Large shadow</div>
<div class="shadow-xl/20">20% opacity shadow</div>
<div class="shadow-blue-500/25">Colored shadow</div>
<!-- Opacity -->
<div class="opacity-50">50% transparent</div>
<!-- Filters -->
<img class="blur-sm" />
<img class="grayscale" />
<div class="backdrop-blur-md bg-white/30">Glass effect</div>Transitions & Animations
Smooth transitions, keyframe animations, and transforms.
Transitions & Transforms
Animate property changes and transform elements.
<!-- Transition on hover -->
<button class="transition-colors duration-200 hover:bg-blue-600">
Smooth color change
</button>
<!-- Scale on hover -->
<div class="transition-transform duration-300 hover:scale-105">
Card
</div>
<!-- Transform -->
<div class="rotate-45">Rotated 45°</div>
<div class="translate-x-4">Moved right</div>Keyframe Animations
Built-in and custom keyframe animations.
<!-- Built-in animations -->
<div class="animate-spin">Spinning loader</div>
<div class="animate-pulse">Pulsing skeleton</div>
<div class="animate-bounce">Bouncing arrow</div>
<div class="animate-ping">Ping notification</div>Responsive Design
Breakpoints, responsive patterns, and container queries.
Breakpoints & Responsive
Mobile-first responsive design with breakpoint prefixes.
<!-- Mobile-first: styles apply from that breakpoint UP -->
<div class="text-sm md:text-base lg:text-lg">
Responsive text
</div>
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
Responsive grid
</div>
<div class="hidden md:block">Only visible on md+</div>
<div class="md:hidden">Only visible on mobile</div>Customization
Customize Tailwind with @theme, @apply, and arbitrary values.
@theme, @apply & Arbitrary Values
Extend the default theme, use utilities in custom CSS, and write one-off values.
/* @theme — customize colors, fonts, spacing (v4) */
@theme {
--color-brand: #3b82f6;
--font-display: "Inter", sans-serif;
}
/* @apply — use Tailwind utilities in custom CSS */
.btn-primary {
@apply bg-blue-500 text-white px-4 py-2 rounded-lg;
}
/* Arbitrary values — one-off custom values */
<div class="w-[347px] bg-[#1a2b3c] top-[117px]">@source, @plugin & @utility
Control source detection, load plugins, and define custom utilities — v4 CSS-first
/* @source — control which files Tailwind scans for classes */
@import "tailwindcss";
@source "../components";
@source "../node_modules/@my/ui";
@source not "./legacy/**";
/* @plugin — load a Tailwind plugin (replaces tailwind.config.js plugins array) */
@plugin "@tailwindcss/typography";
@plugin "@tailwindcss/forms";
/* @utility — define your own utility class */
@utility content-auto {
content-visibility: auto;
}
/* @custom-variant — define a custom variant */
@custom-variant pointer-coarse (@media (pointer: coarse));
/* Now usable as: */
/* class="content-auto pointer-coarse:p-6" */Interactivity & Accessibility
Cursor, scroll behavior, screen readers, and tables.
Cursor, Scroll & Tables
Interactive behavior, scroll snap, and table styling.
<!-- Cursor -->
<button class="cursor-pointer">Clickable</button>
<div class="cursor-not-allowed opacity-50">Disabled</div>
<div class="cursor-grab active:cursor-grabbing">Drag me</div>
<!-- Scroll behavior -->
<div class="scroll-smooth">Smooth scrolling</div>
<div class="overflow-y-auto scrollbar-thin">Custom scrollbar</div>
<!-- Screen reader only -->
<span class="sr-only">Accessible label</span>