Tailwind CSS Cheat Sheet & Quick Reference for 2026

Look Up Any Tailwind Class Instantly

Use our interactive Tailwind CSS Cheat Sheet & Class Lookup tool to search any Tailwind utility class and see the exact CSS it generates. Type a class name or CSS property and get instant results with copy-to-clipboard.

1. Introduction to Tailwind CSS Utility Classes

Tailwind CSS has fundamentally changed how developers write CSS. Instead of creating custom class names like .card-container or .hero-title and writing corresponding CSS rules, Tailwind gives you a comprehensive set of pre-built utility classes that each apply a single CSS property. You compose these utilities directly in your HTML to build any design.

Here is a simple example. In traditional CSS you might write:

<!-- Traditional CSS -->
<div class="card">
  <h2 class="card-title">Hello</h2>
  <p class="card-body">Welcome to Tailwind</p>
</div>

<style>
.card { padding: 1.5rem; background: white; border-radius: 0.5rem; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
.card-title { font-size: 1.25rem; font-weight: 700; margin-bottom: 0.5rem; }
.card-body { color: #6b7280; }
</style>

With Tailwind, you skip the stylesheet entirely:

<!-- Tailwind CSS -->
<div class="p-6 bg-white rounded-lg shadow">
  <h2 class="text-xl font-bold mb-2">Hello</h2>
  <p class="text-gray-500">Welcome to Tailwind</p>
</div>

This utility-first approach offers several concrete advantages:

This cheat sheet covers every major category of Tailwind utility classes with practical examples. Bookmark it, and use our Tailwind Lookup tool whenever you need to quickly check what CSS a specific class generates.

2. Spacing Utilities (Padding, Margin, Gap)

Spacing is arguably the most frequently used category of Tailwind utilities. The framework uses a consistent scale where 1 unit = 0.25rem (4px). This means p-4 is 1rem (16px), m-8 is 2rem (32px), and so on.

The Spacing Scale

Class Suffix Value Pixels
000px
px1px1px
0.50.125rem2px
10.25rem4px
20.5rem8px
30.75rem12px
41rem16px
51.25rem20px
61.5rem24px
82rem32px
102.5rem40px
123rem48px
164rem64px
205rem80px
246rem96px
328rem128px
4812rem192px
6416rem256px
9624rem384px

Padding Classes

Padding utilities follow the pattern p{side}-{size}:

Prefix Applies To Example CSS Output
p-All sidesp-4padding: 1rem
px-Left + Rightpx-6padding-left: 1.5rem; padding-right: 1.5rem
py-Top + Bottompy-2padding-top: 0.5rem; padding-bottom: 0.5rem
pt-Toppt-8padding-top: 2rem
pr-Rightpr-3padding-right: 0.75rem
pb-Bottompb-4padding-bottom: 1rem
pl-Leftpl-5padding-left: 1.25rem
ps-Inline Startps-4padding-inline-start: 1rem
pe-Inline Endpe-4padding-inline-end: 1rem

Margin Classes

Margin utilities follow the same pattern: m{side}-{size}. They also support negative values with a leading dash:

<!-- Positive margin -->
<div class="mt-4">...</div>    <!-- margin-top: 1rem -->
<div class="mx-auto">...</div> <!-- margin-left: auto; margin-right: auto -->

<!-- Negative margin -->
<div class="-mt-2">...</div>   <!-- margin-top: -0.5rem -->
<div class="-mx-4">...</div>   <!-- margin-left: -1rem; margin-right: -1rem -->

The mx-auto utility is one of the most commonly used classes for horizontally centering block elements.

Gap Classes (Flexbox & Grid)

The gap utilities control spacing between flex or grid children without adding margin to individual items:

<!-- Uniform gap -->
<div class="flex gap-4">
  <div>Item 1</div>
  <div>Item 2</div>
  <div>Item 3</div>
</div>

<!-- Different horizontal and vertical gap -->
<div class="grid grid-cols-3 gap-x-8 gap-y-4">
  <div>Card 1</div>
  <div>Card 2</div>
  <div>Card 3</div>
  <div>Card 4</div>
  <div>Card 5</div>
  <div>Card 6</div>
</div>

Space Between

The space-x-* and space-y-* utilities add margin between child elements. They are useful when you want spacing between items but not on the outer edges:

<!-- Horizontal space between items -->
<div class="flex space-x-4">
  <button>Save</button>    <!-- no left margin -->
  <button>Cancel</button>  <!-- margin-left: 1rem -->
  <button>Delete</button>  <!-- margin-left: 1rem -->
</div>

<!-- Vertical space between items -->
<div class="space-y-6">
  <section>First section</section>
  <section>Second section</section>
  <section>Third section</section>
</div>

Tip: Prefer gap over space-* when using flexbox or grid, as gap does not add margin to any child elements and avoids issues with reversed flex order.

3. Typography Utilities

Tailwind provides a comprehensive set of typography utilities covering font size, weight, line height, letter spacing, text alignment, and much more.

Font Size

Class Font Size Line Height
text-xs0.75rem (12px)1rem (16px)
text-sm0.875rem (14px)1.25rem (20px)
text-base1rem (16px)1.5rem (24px)
text-lg1.125rem (18px)1.75rem (28px)
text-xl1.25rem (20px)1.75rem (28px)
text-2xl1.5rem (24px)2rem (32px)
text-3xl1.875rem (30px)2.25rem (36px)
text-4xl2.25rem (36px)2.5rem (40px)
text-5xl3rem (48px)1
text-6xl3.75rem (60px)1
text-7xl4.5rem (72px)1
text-8xl6rem (96px)1
text-9xl8rem (128px)1

Notice that text-base through text-4xl include a default line height, while the larger sizes use a line height of 1 (the font size itself). You can override these with explicit line-height utilities.

Font Weight

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 (Leading)

Tailwind uses the term "leading" (from typography) for line-height utilities:

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

<!-- Fixed line heights -->
leading-3        → line-height: 0.75rem
leading-4        → line-height: 1rem
leading-5        → line-height: 1.25rem
leading-6        → line-height: 1.5rem
leading-7        → line-height: 1.75rem
leading-8        → line-height: 2rem
leading-9        → line-height: 2.25rem
leading-10       → line-height: 2.5rem

Letter Spacing (Tracking)

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 & Decoration

<!-- Alignment -->
<p class="text-left">Left aligned</p>
<p class="text-center">Centered</p>
<p class="text-right">Right aligned</p>
<p class="text-justify">Justified text</p>

<!-- Decoration -->
<span class="underline">Underlined</span>
<span class="line-through">Strikethrough</span>
<span class="no-underline">Remove underline</span>
<span class="underline decoration-wavy decoration-red-500">Wavy red underline</span>

<!-- Transform -->
<span class="uppercase">uppercase text</span>
<span class="lowercase">LOWERCASE TEXT</span>
<span class="capitalize">capitalize each word</span>
<span class="normal-case">Reset to Normal Case</span>

<!-- Overflow -->
<p class="truncate">Very long text that gets truncated with ellipsis...</p>
<p class="text-ellipsis overflow-hidden">Also truncated</p>
<p class="line-clamp-3">Clamp to 3 lines maximum...</p>

Font Family

font-sans   → font-family: ui-sans-serif, system-ui, sans-serif, ...
font-serif  → font-family: ui-serif, Georgia, Cambria, "Times New Roman", serif
font-mono   → font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, monospace

Practical Typography Example

<article class="max-w-prose mx-auto">
  <h1 class="text-4xl font-bold tracking-tight leading-tight mb-4">
    Article Title
  </h1>
  <p class="text-sm text-gray-500 uppercase tracking-wider mb-8">
    February 11, 2026 &bull; 5 min read
  </p>
  <p class="text-lg leading-relaxed text-gray-700">
    Body text with comfortable reading line height and slightly
    larger font size for readability.
  </p>
  <blockquote class="border-l-4 border-blue-500 pl-4 italic text-gray-600">
    A notable quote styled with Tailwind utilities.
  </blockquote>
</article>

4. Flexbox & Grid Shortcuts

Flexbox and CSS Grid are the two primary layout systems in modern CSS, and Tailwind makes both effortless with intuitive utility classes.

Flexbox Essentials

Class CSS Purpose
flexdisplay: flexCreate flex container
inline-flexdisplay: inline-flexInline flex container
flex-rowflex-direction: rowHorizontal layout (default)
flex-colflex-direction: columnVertical layout
flex-row-reverseflex-direction: row-reverseReverse horizontal
flex-col-reverseflex-direction: column-reverseReverse vertical
flex-wrapflex-wrap: wrapAllow wrapping
flex-nowrapflex-wrap: nowrapPrevent wrapping
flex-1flex: 1 1 0%Grow and shrink equally
flex-autoflex: 1 1 autoGrow/shrink based on size
flex-noneflex: nonePrevent grow/shrink
growflex-grow: 1Allow growing
shrink-0flex-shrink: 0Prevent shrinking

Alignment in Flexbox

<!-- Justify Content (main axis) -->
justify-start    → justify-content: flex-start
justify-center   → justify-content: center
justify-end      → justify-content: flex-end
justify-between  → justify-content: space-between
justify-around   → justify-content: space-around
justify-evenly   → justify-content: space-evenly

<!-- Align Items (cross axis) -->
items-start      → align-items: flex-start
items-center     → align-items: center
items-end        → align-items: flex-end
items-baseline   → align-items: baseline
items-stretch    → align-items: stretch

Common Flexbox Patterns

<!-- Center content both axes -->
<div class="flex items-center justify-center h-screen">
  <p>Perfectly centered</p>
</div>

<!-- Navbar with logo left, links right -->
<nav class="flex items-center justify-between px-6 py-4">
  <a href="/" class="text-xl font-bold">Logo</a>
  <div class="flex gap-6">
    <a href="/about">About</a>
    <a href="/contact">Contact</a>
  </div>
</nav>

<!-- Sidebar layout -->
<div class="flex min-h-screen">
  <aside class="w-64 shrink-0 bg-gray-800">Sidebar</aside>
  <main class="flex-1 p-8">Main content</main>
</div>

<!-- Footer pushed to bottom -->
<div class="flex flex-col min-h-screen">
  <header>Header</header>
  <main class="flex-1">Content</main>
  <footer>Always at the bottom</footer>
</div>

CSS Grid Essentials

Class CSS
griddisplay: grid
grid-cols-1 to grid-cols-12grid-template-columns: repeat(n, minmax(0, 1fr))
grid-rows-1 to grid-rows-6grid-template-rows: repeat(n, minmax(0, 1fr))
col-span-1 to col-span-12grid-column: span n / span n
col-start-1 to col-start-13grid-column-start: n
row-span-1 to row-span-6grid-row: span n / span n
grid-cols-nonegrid-template-columns: none
col-span-fullgrid-column: 1 / -1

Practical Grid Layouts

<!-- Responsive card grid -->
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
  <div class="bg-white rounded-lg p-6 shadow">Card 1</div>
  <div class="bg-white rounded-lg p-6 shadow">Card 2</div>
  <div class="bg-white rounded-lg p-6 shadow">Card 3</div>
</div>

<!-- Dashboard layout with sidebar -->
<div class="grid grid-cols-[250px_1fr] min-h-screen">
  <aside class="bg-gray-900 p-4">Sidebar</aside>
  <main class="p-8">Dashboard content</main>
</div>

<!-- Blog layout: featured + grid -->
<div class="grid grid-cols-2 gap-6">
  <article class="col-span-2 h-96 bg-cover bg-center rounded-xl">
    Featured Post
  </article>
  <article class="h-64 bg-white rounded-lg">Post 2</article>
  <article class="h-64 bg-white rounded-lg">Post 3</article>
</div>

<!-- Auto-fit responsive grid (no breakpoints needed) -->
<div class="grid grid-cols-[repeat(auto-fit,minmax(250px,1fr))] gap-4">
  <div>Auto-sizing card</div>
  <div>Auto-sizing card</div>
  <div>Auto-sizing card</div>
  <div>Auto-sizing card</div>
</div>

CSS Layout Tools

Need help with CSS layouts beyond Tailwind? Try our CSS Gradient Generator, CSS Animation Generator, or Box Shadow Generator to create styles you can use anywhere.

5. Responsive Design Breakpoints

Tailwind uses a mobile-first breakpoint system. Unprefixed utilities apply at all screen sizes, and responsive prefixes apply at that breakpoint and above.

Default Breakpoints

Prefix Min Width CSS Media Query Typical Device
(none)0pxNo media queryAll devices
sm:640px@media (min-width: 640px)Large phones / small tablets
md:768px@media (min-width: 768px)Tablets
lg:1024px@media (min-width: 1024px)Laptops
xl:1280px@media (min-width: 1280px)Desktops
2xl:1536px@media (min-width: 1536px)Large desktops

How Mobile-First Works

The key mental model: start with mobile styles, then add overrides for larger screens. Do not think "hide this on mobile" -- instead think "show this from md and up."

<!-- Mobile: 1 column, Tablet: 2 columns, Desktop: 3 columns -->
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
  ...
</div>

<!-- Mobile: stacked, Desktop: side by side -->
<div class="flex flex-col lg:flex-row gap-8">
  <div class="lg:w-2/3">Main content</div>
  <div class="lg:w-1/3">Sidebar</div>
</div>

<!-- Mobile: small text, larger on bigger screens -->
<h1 class="text-2xl sm:text-3xl md:text-4xl lg:text-5xl">
  Responsive Heading
</h1>

<!-- Hide on mobile, show on desktop -->
<nav class="hidden lg:flex gap-6">
  <a href="#">Home</a>
  <a href="#">About</a>
</nav>

<!-- Show mobile menu button, hide on desktop -->
<button class="lg:hidden">Menu</button>

<!-- Responsive padding -->
<section class="px-4 sm:px-6 lg:px-8 xl:px-12">
  Content with increasing padding on wider screens
</section>

Container Utility

Tailwind's container class sets a responsive max-width at each breakpoint:

<!-- Centers content with responsive max-width -->
<div class="container mx-auto px-4">
  <!-- sm: max-width: 640px  -->
  <!-- md: max-width: 768px  -->
  <!-- lg: max-width: 1024px -->
  <!-- xl: max-width: 1280px -->
  <!-- 2xl: max-width: 1536px -->
</div>

<!-- Or use max-w utilities for more control -->
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
  Constrained content area
</div>

Max-Width Utilities for Content

Class Max Width Use Case
max-w-xs20rem (320px)Small cards, dropdowns
max-w-sm24rem (384px)Form fields, small panels
max-w-md28rem (448px)Login forms, modals
max-w-lg32rem (512px)Content cards
max-w-xl36rem (576px)Article content
max-w-2xl42rem (672px)Blog posts
max-w-4xl56rem (896px)Wide content areas
max-w-7xl80rem (1280px)Page wrappers
max-w-prose65chReadable text width
max-w-screen-xl1280pxFull screen sections

6. Colors and Backgrounds

Tailwind ships with an extensive color palette. Each color has shades from 50 (lightest) to 950 (darkest), giving you fine-grained control over your design.

Color Naming Pattern

Colors follow the pattern {property}-{color}-{shade}:

<!-- Text color -->
<p class="text-blue-500">Blue text</p>
<p class="text-gray-700">Dark gray text</p>
<p class="text-red-600">Red text</p>

<!-- Background color -->
<div class="bg-blue-500">Blue background</div>
<div class="bg-gray-100">Light gray background</div>

<!-- Border color -->
<input class="border border-gray-300 focus:border-blue-500" />

<!-- Ring (outline/focus ring) color -->
<button class="ring-2 ring-blue-500">Focused button</button>

Available Colors

The default palette includes these color families:

Each color has shades: 50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950.

Opacity Modifiers

You can add opacity to any color using the slash syntax:

<!-- 50% opacity blue background -->
<div class="bg-blue-500/50">Semi-transparent blue</div>

<!-- 75% opacity text -->
<p class="text-black/75">Slightly transparent black text</p>

<!-- 10% opacity border -->
<div class="border border-white/10">Subtle border</div>

<!-- Common opacity values -->
<div class="bg-black/0">Transparent</div>
<div class="bg-black/5">Barely visible</div>
<div class="bg-black/25">25% opacity</div>
<div class="bg-black/50">50% opacity</div>
<div class="bg-black/75">75% opacity</div>
<div class="bg-black/100">Fully opaque</div>

Gradients

Tailwind has built-in gradient utilities:

<!-- Linear gradient from left to right -->
<div class="bg-gradient-to-r from-blue-500 to-purple-600">
  Gradient background
</div>

<!-- Three-stop gradient -->
<div class="bg-gradient-to-r from-green-400 via-blue-500 to-purple-600">
  Three-color gradient
</div>

<!-- Gradient directions -->
bg-gradient-to-t     → top
bg-gradient-to-tr    → top right
bg-gradient-to-r     → right
bg-gradient-to-br    → bottom right
bg-gradient-to-b     → bottom
bg-gradient-to-bl    → bottom left
bg-gradient-to-l     → left
bg-gradient-to-tl    → top left

<!-- Gradient button example -->
<button class="bg-gradient-to-r from-cyan-500 to-blue-500
               hover:from-cyan-600 hover:to-blue-600
               text-white px-6 py-3 rounded-lg font-semibold">
  Gradient Button
</button>

For more complex gradients, try our CSS Gradient Generator which lets you visually create gradients and copy the CSS.

Arbitrary Color Values

<!-- Use any hex, RGB, or HSL color -->
<div class="bg-[#1da1f2]">Twitter blue</div>
<div class="text-[rgb(255,0,128)]">Custom pink</div>
<div class="border-[hsl(210,100%,50%)]">HSL blue border</div>

7. Hover, Focus, and State Variants

Tailwind lets you apply utilities conditionally based on interactive states by prefixing any utility with a state variant. This replaces traditional CSS pseudo-class selectors.

Interactive State Variants

Variant CSS Equivalent When Applied
hover::hoverMouse over the element
focus::focusElement is focused (keyboard/click)
focus-within::focus-withinAny child is focused
focus-visible::focus-visibleFocused via keyboard only
active::activeElement is being pressed
visited::visitedLink has been visited
disabled::disabledForm element is disabled
checked::checkedCheckbox/radio is checked
required::requiredForm element is required
invalid::invalidForm validation failed
placeholder:::placeholderPlaceholder text styling

Practical State Examples

<!-- Interactive button with transitions -->
<button class="bg-blue-500 hover:bg-blue-600 active:bg-blue-700
               text-white px-4 py-2 rounded-lg
               transition-colors duration-200
               focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2
               disabled:opacity-50 disabled:cursor-not-allowed">
  Click Me
</button>

<!-- Form input with states -->
<input class="w-full px-4 py-2 border border-gray-300 rounded-lg
              focus:border-blue-500 focus:ring-2 focus:ring-blue-500/20
              placeholder:text-gray-400 placeholder:italic
              invalid:border-red-500 invalid:text-red-600
              disabled:bg-gray-100 disabled:text-gray-500"
       type="email" placeholder="Enter your email" required />

<!-- Card with hover effect -->
<div class="bg-white rounded-xl p-6 shadow-sm
            hover:shadow-lg hover:-translate-y-1
            transition-all duration-300">
  <h3 class="font-semibold">Hover to lift</h3>
</div>

<!-- Link with underline on hover -->
<a href="#" class="text-blue-500 hover:text-blue-700
                   no-underline hover:underline
                   transition-colors">
  Hover me
</a>

Group and Peer Variants

These are powerful variants for styling elements based on the state of a different element:

<!-- Group: style children when parent is hovered -->
<div class="group bg-white rounded-lg p-6 hover:bg-blue-500 transition-colors">
  <h3 class="text-gray-900 group-hover:text-white">Card Title</h3>
  <p class="text-gray-500 group-hover:text-blue-100">Card description</p>
  <span class="text-blue-500 group-hover:text-white
               translate-x-0 group-hover:translate-x-2
               transition-all inline-block">
    Learn more &rarr;
  </span>
</div>

<!-- Peer: style element based on sibling state -->
<label>
  <input type="checkbox" class="peer sr-only" />
  <span class="block w-10 h-6 bg-gray-300 rounded-full
               peer-checked:bg-blue-500 transition-colors"></span>
</label>

<!-- Peer: show validation message -->
<input type="email" class="peer" required />
<p class="hidden peer-invalid:block text-red-500 text-sm mt-1">
  Please enter a valid email address.
</p>

Structural Variants

<!-- Style first and last children -->
<ul>
  <li class="first:pt-0 last:pb-0 py-4 border-b last:border-0">Item</li>
</ul>

<!-- Alternate row colors -->
<tr class="odd:bg-white even:bg-gray-50">...</tr>

<!-- Style empty states -->
<div class="empty:hidden"></div>

8. Custom Configuration Tips

While Tailwind's defaults are excellent, most projects need some customization. Here are the most common and useful configuration patterns.

Extending the Theme (v3)

// tailwind.config.js
module.exports = {
  theme: {
    extend: {
      // Add custom colors alongside defaults
      colors: {
        brand: {
          50: '#eff6ff',
          100: '#dbeafe',
          500: '#3b82f6',
          600: '#2563eb',
          700: '#1d4ed8',
          900: '#1e3a5f',
        },
      },

      // Add custom spacing values
      spacing: {
        '18': '4.5rem',
        '88': '22rem',
        '128': '32rem',
      },

      // Add custom font family
      fontFamily: {
        display: ['Cal Sans', 'Inter', 'sans-serif'],
        body: ['Inter', 'system-ui', 'sans-serif'],
      },

      // Add custom breakpoints
      screens: {
        '3xl': '1800px',
        'tall': { 'raw': '(min-height: 800px)' },
      },

      // Custom animations
      animation: {
        'fade-in': 'fadeIn 0.5s ease-out',
        'slide-up': 'slideUp 0.3s ease-out',
      },
      keyframes: {
        fadeIn: {
          '0%': { opacity: '0' },
          '100%': { opacity: '1' },
        },
        slideUp: {
          '0%': { transform: 'translateY(10px)', opacity: '0' },
          '100%': { transform: 'translateY(0)', opacity: '1' },
        },
      },
    },
  },
};

Arbitrary Values

For one-off values that do not belong in your design system, use square bracket notation instead of modifying the config:

<!-- Arbitrary spacing -->
<div class="w-[137px] h-[68px] top-[117px]">...</div>

<!-- Arbitrary colors -->
<div class="bg-[#1da1f2] text-[rgb(255,255,255)]">...</div>

<!-- Arbitrary grid template -->
<div class="grid grid-cols-[200px_1fr_200px]">...</div>

<!-- Arbitrary font size with clamp -->
<h1 class="text-[clamp(1.5rem,4vw,3rem)]">Fluid text</h1>

<!-- Arbitrary media query -->
<div class="[@media(min-width:900px)]:flex">...</div>

<!-- Arbitrary CSS property (v3.4+) -->
<div class="[mask-image:linear-gradient(to_bottom,black,transparent)]">...</div>

Using @apply for Reusable Styles

If you find yourself repeating the same combination of utilities, extract them with @apply:

/* In your CSS file */
@layer components {
  .btn {
    @apply px-4 py-2 rounded-lg font-semibold transition-colors;
  }

  .btn-primary {
    @apply btn bg-blue-500 text-white hover:bg-blue-600;
  }

  .btn-secondary {
    @apply btn bg-gray-200 text-gray-800 hover:bg-gray-300;
  }

  .input {
    @apply w-full px-4 py-2 border border-gray-300 rounded-lg
           focus:border-blue-500 focus:ring-2 focus:ring-blue-500/20
           placeholder:text-gray-400;
  }

  .card {
    @apply bg-white rounded-xl p-6 shadow-sm hover:shadow-md transition-shadow;
  }
}

Important: Use @apply sparingly. The Tailwind team recommends it primarily for very commonly repeated patterns. In most cases, extracting a component in your framework (React component, Vue component, etc.) is a better approach than @apply.

Tailwind Plugins

Useful official and community plugins:

// tailwind.config.js
module.exports = {
  plugins: [
    require('@tailwindcss/typography'),  // Prose class for rich text
    require('@tailwindcss/forms'),       // Better default form styles
    require('@tailwindcss/aspect-ratio'),// Aspect ratio utilities
    require('@tailwindcss/container-queries'), // @container support
  ],
};

The @tailwindcss/typography plugin is especially useful. It provides a prose class that styles rendered HTML (from Markdown or a CMS) with sensible defaults:

<article class="prose prose-lg prose-blue max-w-prose mx-auto">
  <!-- All headings, paragraphs, lists, code blocks, tables, etc.
       are styled automatically -->
  <h1>My Blog Post</h1>
  <p>This paragraph has good typography defaults.</p>
  <pre><code>console.log("styled code block")</code></pre>
</article>

9. Dark Mode

Tailwind CSS has first-class support for dark mode with the dark: variant. You can style any element differently in dark mode without writing a single media query or custom CSS class.

Configuration Options

// tailwind.config.js (v3)
module.exports = {
  // Option 1: Use OS preference (default)
  darkMode: 'media',

  // Option 2: Use class-based toggling
  darkMode: 'class',

  // Option 3: Use a custom selector (v3.4+)
  darkMode: ['selector', '[data-theme="dark"]'],
};

Dark Mode Utilities in Practice

<!-- Page with dark mode support -->
<body class="bg-white dark:bg-gray-900 text-gray-900 dark:text-gray-100">

  <!-- Card component -->
  <div class="bg-white dark:bg-gray-800
              border border-gray-200 dark:border-gray-700
              rounded-xl p-6 shadow-sm dark:shadow-gray-900/30">
    <h2 class="text-gray-900 dark:text-white font-bold">Card Title</h2>
    <p class="text-gray-600 dark:text-gray-300 mt-2">Card description</p>
    <button class="mt-4 bg-blue-500 dark:bg-blue-600
                   hover:bg-blue-600 dark:hover:bg-blue-700
                   text-white px-4 py-2 rounded-lg">
      Action
    </button>
  </div>

  <!-- Form input -->
  <input class="bg-white dark:bg-gray-800
                border-gray-300 dark:border-gray-600
                text-gray-900 dark:text-white
                placeholder:text-gray-400 dark:placeholder:text-gray-500" />

  <!-- Code block -->
  <pre class="bg-gray-100 dark:bg-gray-900
              text-gray-800 dark:text-gray-200
              border border-gray-200 dark:border-gray-700
              rounded-lg p-4">
    <code>const x = 42;</code>
  </pre>

</body>

Dark Mode Toggle with JavaScript

// For class-based dark mode
function toggleDarkMode() {
  const html = document.documentElement;

  if (html.classList.contains('dark')) {
    html.classList.remove('dark');
    localStorage.setItem('theme', 'light');
  } else {
    html.classList.add('dark');
    localStorage.setItem('theme', 'dark');
  }
}

// Apply saved preference on page load
function initTheme() {
  const saved = localStorage.getItem('theme');
  const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;

  if (saved === 'dark' || (!saved && prefersDark)) {
    document.documentElement.classList.add('dark');
  }
}

// Call on load (add to <head> to prevent flash)
initTheme();

Dark Mode Design Tips

10. Tailwind v4 Changes and Improvements

Tailwind CSS v4 is a major release that rethinks the framework's architecture while keeping the utility-class approach developers love. Here are the most significant changes.

New Oxide Engine

The biggest under-the-hood change is the new Oxide engine, rewritten in Rust. This delivers:

CSS-First Configuration

The JavaScript config file (tailwind.config.js) is replaced with CSS-native configuration using @theme:

/* v3: tailwind.config.js */
module.exports = {
  theme: {
    extend: {
      colors: {
        brand: '#3b82f6',
      },
      fontFamily: {
        display: ['Cal Sans', 'sans-serif'],
      },
    },
  },
};

/* v4: your main CSS file */
@import "tailwindcss";

@theme {
  --color-brand: #3b82f6;
  --font-display: "Cal Sans", sans-serif;

  --breakpoint-3xl: 1800px;

  --animate-fade-in: fade-in 0.5s ease-out;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

Automatic Content Detection

In v3, you had to configure which files Tailwind should scan:

// v3: tailwind.config.js
module.exports = {
  content: [
    './src/**/*.{js,ts,jsx,tsx}',
    './components/**/*.{js,ts,jsx,tsx}',
  ],
};

In v4, content detection is automatic. Tailwind scans your project and finds template files without any configuration. You can still override this if needed, but for most projects it just works.

CSS Cascade Layers

Tailwind v4 uses native CSS @layer for managing specificity, making it easier to override Tailwind styles when needed and reducing specificity conflicts:

/* v4 generates CSS with proper cascade layers */
@layer theme, base, components, utilities;

@layer base {
  /* Reset and base styles */
}

@layer utilities {
  /* All utility classes */
}

New and Updated Utilities

Feature v3 v4
Container queriesPlugin requiredBuilt-in (@container, @sm:, @md:)
3D transformsNot includedBuilt-in (rotate-x-*, rotate-y-*, perspective-*)
Field sizingNot includedfield-sizing-content for auto-growing textareas
Color mixingNot includedbg-red-500/oklch and color-mix support
Not variantNot includednot-hover:, not-first:, etc.
Starting styleNot includedstarting: for entry animations
Inert variantNot includedinert: for inert elements

Migration from v3 to v4

Tailwind provides an automated upgrade tool:

# Run the upgrade tool
npx @tailwindcss/upgrade

# This tool:
# - Converts tailwind.config.js to CSS @theme directives
# - Updates deprecated class names
# - Removes unnecessary PostCSS config
# - Updates your package.json dependencies

Most utility class names remain the same, so your HTML templates typically need minimal changes. The biggest migration effort is moving configuration from JavaScript to CSS.

11. Common Patterns and Recipes

Here are battle-tested Tailwind patterns you can copy directly into your projects.

Responsive Navigation Bar

<nav class="bg-white dark:bg-gray-900 shadow-sm">
  <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
    <div class="flex items-center justify-between h-16">
      <!-- Logo -->
      <a href="/" class="text-xl font-bold text-gray-900 dark:text-white">
        MyApp
      </a>

      <!-- Desktop Links -->
      <div class="hidden md:flex items-center gap-8">
        <a href="#" class="text-gray-600 hover:text-gray-900
                          dark:text-gray-300 dark:hover:text-white
                          transition-colors">Features</a>
        <a href="#" class="text-gray-600 hover:text-gray-900
                          dark:text-gray-300 dark:hover:text-white
                          transition-colors">Pricing</a>
        <a href="#" class="bg-blue-500 hover:bg-blue-600 text-white
                          px-4 py-2 rounded-lg transition-colors">
          Get Started
        </a>
      </div>

      <!-- Mobile Menu Button -->
      <button class="md:hidden p-2 rounded-lg hover:bg-gray-100
                     dark:hover:bg-gray-800">
        <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
          <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                d="M4 6h16M4 12h16M4 18h16"/>
        </svg>
      </button>
    </div>
  </div>
</nav>

Hero Section

<section class="relative overflow-hidden bg-gradient-to-br
                from-blue-600 via-purple-600 to-indigo-700
                text-white py-24 sm:py-32">
  <div class="max-w-4xl mx-auto px-4 text-center">
    <h1 class="text-4xl sm:text-5xl lg:text-6xl font-extrabold
               tracking-tight leading-tight mb-6">
      Build faster with utility-first CSS
    </h1>
    <p class="text-lg sm:text-xl text-blue-100 max-w-2xl mx-auto mb-10">
      Tailwind CSS makes it easy to build modern, responsive
      interfaces without leaving your HTML.
    </p>
    <div class="flex flex-col sm:flex-row gap-4 justify-center">
      <a href="#" class="bg-white text-blue-600 px-8 py-3 rounded-lg
                         font-semibold hover:bg-blue-50 transition-colors">
        Get Started
      </a>
      <a href="#" class="border-2 border-white/30 px-8 py-3 rounded-lg
                         font-semibold hover:bg-white/10 transition-colors">
        View Docs
      </a>
    </div>
  </div>
</section>

Pricing Card

<div class="bg-white dark:bg-gray-800 rounded-2xl shadow-xl
            border-2 border-blue-500 p-8 relative">
  <div class="absolute -top-4 left-1/2 -translate-x-1/2
              bg-blue-500 text-white text-sm font-bold
              px-4 py-1 rounded-full">
    Most Popular
  </div>
  <h3 class="text-xl font-bold text-gray-900 dark:text-white">Pro</h3>
  <div class="mt-4 flex items-baseline gap-1">
    <span class="text-5xl font-extrabold text-gray-900 dark:text-white">$29</span>
    <span class="text-gray-500">/month</span>
  </div>
  <ul class="mt-8 space-y-4">
    <li class="flex items-center gap-3 text-gray-600 dark:text-gray-300">
      <svg class="w-5 h-5 text-green-500 shrink-0" fill="currentColor" viewBox="0 0 20 20">
        <path fill-rule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z"/>
      </svg>
      Unlimited projects
    </li>
    <li class="flex items-center gap-3 text-gray-600 dark:text-gray-300">
      <svg class="w-5 h-5 text-green-500 shrink-0" fill="currentColor" viewBox="0 0 20 20">
        <path fill-rule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z"/>
      </svg>
      Priority support
    </li>
  </ul>
  <button class="mt-8 w-full bg-blue-500 hover:bg-blue-600 text-white
                 py-3 rounded-lg font-semibold transition-colors">
    Start Free Trial
  </button>
</div>

Animated Loading Spinner

<!-- Simple spinner -->
<div class="animate-spin h-8 w-8 border-4 border-blue-500
            border-t-transparent rounded-full"></div>

<!-- Spinner with text -->
<div class="flex items-center gap-3">
  <div class="animate-spin h-5 w-5 border-2 border-blue-500
              border-t-transparent rounded-full"></div>
  <span class="text-gray-500">Loading...</span>
</div>

<!-- Pulse skeleton loader -->
<div class="animate-pulse space-y-4">
  <div class="h-4 bg-gray-200 dark:bg-gray-700 rounded w-3/4"></div>
  <div class="h-4 bg-gray-200 dark:bg-gray-700 rounded w-full"></div>
  <div class="h-4 bg-gray-200 dark:bg-gray-700 rounded w-5/6"></div>
</div>

Responsive Image with Aspect Ratio

<!-- Fixed aspect ratio image -->
<div class="aspect-video rounded-xl overflow-hidden">
  <img src="hero.jpg" alt="Hero"
       class="w-full h-full object-cover" />
</div>

<!-- Avatar -->
<img src="avatar.jpg" alt="User"
     class="w-12 h-12 rounded-full object-cover ring-2 ring-white" />

<!-- Image gallery grid -->
<div class="grid grid-cols-2 md:grid-cols-3 gap-2">
  <div class="aspect-square rounded-lg overflow-hidden">
    <img src="photo1.jpg" class="w-full h-full object-cover
                                  hover:scale-110 transition-transform duration-300" />
  </div>
  <!-- more items... -->
</div>

Toast Notification

<div class="fixed bottom-4 right-4 z-50
            flex items-center gap-3
            bg-green-500 text-white px-6 py-4 rounded-xl shadow-lg
            animate-[slideUp_0.3s_ease-out]">
  <svg class="w-5 h-5 shrink-0" fill="currentColor" viewBox="0 0 20 20">
    <path fill-rule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z"/>
  </svg>
  <p class="font-medium">Changes saved successfully!</p>
  <button class="ml-2 hover:bg-green-600 rounded p-1">
    &times;
  </button>
</div>

Sticky Table Header

<div class="overflow-auto max-h-96 rounded-lg border border-gray-200 dark:border-gray-700">
  <table class="w-full text-left">
    <thead class="sticky top-0 bg-gray-50 dark:bg-gray-800">
      <tr>
        <th class="px-4 py-3 font-semibold text-gray-900 dark:text-white">Name</th>
        <th class="px-4 py-3 font-semibold text-gray-900 dark:text-white">Email</th>
        <th class="px-4 py-3 font-semibold text-gray-900 dark:text-white">Role</th>
      </tr>
    </thead>
    <tbody class="divide-y divide-gray-200 dark:divide-gray-700">
      <tr class="hover:bg-gray-50 dark:hover:bg-gray-800/50">
        <td class="px-4 py-3 text-gray-700 dark:text-gray-300">Alice</td>
        <td class="px-4 py-3 text-gray-500">alice@example.com</td>
        <td class="px-4 py-3">
          <span class="bg-green-100 text-green-700 text-xs font-medium
                       px-2.5 py-0.5 rounded-full">Admin</span>
        </td>
      </tr>
    </tbody>
  </table>
</div>

Generate CSS Effects Visually

Need custom CSS beyond Tailwind's defaults? Use our Box Shadow Generator for custom shadows, CSS Clip Path Generator for creative shapes, or CSS Animation Generator to create keyframe animations.

Utility Class Quick Reference Card

Here is a concise reference for the most-reached-for utilities you will use daily:

Category Most Common Classes
Displayblock, inline-block, flex, grid, hidden
Positionrelative, absolute, fixed, sticky
Widthw-full, w-auto, w-1/2, w-screen, w-fit
Heighth-full, h-screen, h-auto, min-h-screen
Overflowoverflow-hidden, overflow-auto, overflow-scroll
Borderborder, border-2, rounded-lg, rounded-full
Shadowshadow-sm, shadow, shadow-lg, shadow-xl
Opacityopacity-0, opacity-50, opacity-100
Cursorcursor-pointer, cursor-not-allowed, cursor-default
Transitiontransition-all, transition-colors, duration-200, ease-in-out
Z-Indexz-0, z-10, z-20, z-50, z-auto
Pointer Eventspointer-events-none, pointer-events-auto
User Selectselect-none, select-text, select-all

Search Tailwind Classes Interactively

Bookmark our Tailwind CSS Cheat Sheet & Class Lookup for instant search across every Tailwind utility. Type any class name or CSS property and see the generated CSS immediately.

Conclusion

Tailwind CSS has earned its place as the most popular utility-first CSS framework because it solves real problems: inconsistent designs, bloated stylesheets, naming fatigue, and the constant context-switching between HTML and CSS files. By composing small, predictable utility classes directly in your markup, you can build production-quality interfaces faster than ever.

The key to mastering Tailwind is not memorizing every class -- it is understanding the patterns. Once you internalize the spacing scale (1 unit = 0.25rem), the responsive prefix system (mobile-first, breakpoint and up), and the state variant syntax (hover:, focus:, dark:), you can intuit nearly any class name without looking it up.

For the times you do need a quick reference, keep our Tailwind CSS Lookup tool open in a browser tab. It gives you instant search across every utility class with the exact CSS output.

Whether you are starting a new project with Tailwind v4 or maintaining a v3 codebase, the utility-first approach will make your CSS more maintainable, your designs more consistent, and your development faster.

Frequently Asked Questions

What is the difference between Tailwind CSS v3 and v4?

Tailwind CSS v4 brings major architectural changes: it uses a new Oxide engine written in Rust for significantly faster builds, replaces the JavaScript config file (tailwind.config.js) with CSS-native @theme directives, introduces automatic content detection so you no longer need to configure content paths, and adds native support for CSS cascade layers. The utility class syntax remains largely backward-compatible, though some class names have been updated.

How do responsive breakpoints work in Tailwind CSS?

Tailwind uses a mobile-first breakpoint system. Unprefixed utilities apply at all screen sizes, while prefixed utilities like sm:, md:, lg:, xl:, and 2xl: only apply at the specified breakpoint and above. For example, text-sm md:text-base lg:text-lg makes text small on mobile, medium on tablets, and large on desktops. The default breakpoints are sm (640px), md (768px), lg (1024px), xl (1280px), and 2xl (1536px).

How do I enable dark mode in Tailwind CSS?

Tailwind CSS supports dark mode via the dark: variant. By default it uses the prefers-color-scheme media query, but you can switch to class-based dark mode by setting darkMode to 'class' in your config (v3) or using @variant in v4. Then prefix any utility with dark: to apply it in dark mode, like bg-white dark:bg-gray-900 text-black dark:text-white.

What is the Tailwind CSS spacing scale?

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), p-8 is 2rem (32px), and so on. The scale goes from 0 to 96 (24rem/384px) with additional fractional values like 0.5, 1.5, 2.5, and 3.5. This same scale applies to margin, width, height, gap, and other spacing properties.

Can I use custom values in Tailwind CSS without modifying the config?

Yes, Tailwind CSS supports arbitrary values using square bracket notation. You can write classes like w-[137px], bg-[#1da1f2], text-[clamp(1rem,2.5vw,2rem)], or grid-cols-[200px_1fr_200px] to use any CSS value without touching your configuration. This feature works with virtually every utility and is great for one-off values.

How does Tailwind CSS purge unused styles?

Tailwind CSS scans your source files to detect which utility classes you are actually using and only generates CSS for those classes. In v3, you configure content paths in tailwind.config.js. In v4, content detection is automatic. The result is production CSS typically under 10KB gzipped. You should never dynamically construct class names (like text-${color}-500) because the scanner looks for complete class strings in your source code.