Tailwind CSS Patterns (v4 - 2025)
Modern utility-first CSS with CSS-native configuration.
When to Use
Use this skill when configuring Tailwind v4, using CSS-first theme and design tokens, or implementing container queries and modern Tailwind patterns.
1. Tailwind v4 Architecture
What Changed from v3
| v3 (Legacy) |
v4 (Current) |
tailwind.config.js |
CSS-based @theme directive |
| PostCSS plugin |
Oxide engine (10x faster) |
| JIT mode |
Native, always-on |
| Plugin system |
CSS-native features |
@apply directive |
Still works, discouraged |
v4 Core Concepts
| Concept |
Description |
| CSS-first |
Configuration in CSS, not JavaScript |
| Oxide Engine |
Rust-based compiler, much faster |
| Native Nesting |
CSS nesting without PostCSS |
| CSS Variables |
All tokens exposed as --* vars |
2. CSS-Based Configuration
Theme Definition
@theme {
/* Colors - use semantic names */
--color-primary: oklch(0.7 0.15 250);
--color-surface: oklch(0.98 0 0);
--color-surface-dark: oklch(0.15 0 0);
/* Spacing scale */
--spacing-xs: 0.25rem;
--spacing-sm: 0.5rem;
--spacing-md: 1rem;
--spacing-lg: 2rem;
/* Typography */
--font-sans: 'Inter', system-ui, sans-serif;
--font-mono: 'JetBrains Mono', monospace;
}
When to Extend vs Override
| Action |
Use When |
| Extend |
Adding new values alongside defaults |
| Override |
Replacing default scale entirely |
| Semantic tokens |
Project-specific naming (primary, surface) |
3. Container Queries (v4 Native)
Breakpoint vs Container
| Type |
Responds To |
Breakpoint (md:) |
Viewport width |
Container (@container) |
Parent element width |
Container Query Usage
| Pattern |
Classes |
| Define container |
@container on parent |
| Container breakpoint |
@sm:, @md:, @lg: on children |
| Named containers |
@container/card for specificity |
When to Use
| Scenario |
Use |
| Page-level layouts |
Viewport breakpoints |
| Component-level responsive |
Container queries |
| Reusable components |
Container queries (context-independent) |
4. Responsive Design
Breakpoint System
| Prefix |
Min Width |
Target |
| (none) |
0px |
Mobile-first base |
sm: |
640px |
Large phone / small tablet |
md: |
768px |
Tablet |
lg: |
1024px |
Laptop |
xl: |
1280px |
Desktop |
2xl: |
1536px |
Large desktop |
Mobile-First Principle
- Write mobile styles first (no prefix)
- Add larger screen overrides with prefixes
- Example:
w-full md:w-1/2 lg:w-1/3
5. Dark Mode
Configuration Strategies
| Method |
Behavior |
Use When |
class |
.dark class toggles |
Manual theme switcher |
media |
Follows system preference |
No user control |
selector |
Custom selector (v4) |
Complex theming |
Dark Mode Pattern
| Element |
Light |
Dark |
| Background |
bg-white |
dark:bg-zinc-900 |
| Text |
text-zinc-900 |
dark:text-zinc-100 |
| Borders |
border-zinc-200 |
dark:border-zinc-700 |
6. Modern Layout Patterns
Flexbox Patterns
| Pattern |
Classes |
| Center (both axes) |
flex items-center justify-center |
| Vertical stack |
flex flex-col gap-4 |
| Horizontal row |
flex gap-4 |
| Space between |
flex justify-between items-center |
| Wrap grid |
flex flex-wrap gap-4 |
Grid Patterns
| Pattern |
Classes |
| Auto-fit responsive |
grid grid-cols-[repeat(auto-fit,minmax(250px,1fr))] |
| Asymmetric (Bento) |
grid grid-cols-3 grid-rows-2 with spans |
| Sidebar layout |
grid grid-cols-[auto_1fr] |
Note: Prefer asymmetric/Bento layouts over symmetric 3-column grids.
7. Modern Color System
OKLCH vs RGB/HSL
| Format |
Advantage |
| OKLCH |
Perceptually uniform, better for design |
| HSL |
Intuitive hue/saturation |
| RGB |
Legacy compatibility |
Color Token Architecture
| Layer |
Example |
Purpose |
| Primitive |
--blue-500 |
Raw color values |
| Semantic |
--color-primary |
Purpose-based naming |
| Component |
--button-bg |
Component-specific |
8. Typography System
Font Stack Pattern
| Type |
Recommended |
| Sans |
'Inter', 'SF Pro', system-ui, sans-serif |
| Mono |
'JetBrains Mono', 'Fira Code', monospace |
| Display |
'Outfit', 'Poppins', sans-serif |
Type Scale
| Class |
Size |
Use |
text-xs |
0.75rem |
Labels, captions |
text-sm |
0.875rem |
Secondary text |
text-base |
1rem |
Body text |
text-lg |
1.125rem |
Lead text |
text-xl+ |
1.25rem+ |
Headings |
9. Animation &
1---2name: tailwind-patterns3description: Tailwind CSS v4 principles. CSS-first configuration, container queries, modern patterns, design token architecture.4---567# Tailwind CSS Patterns (v4 - 2025)89> Modern utility-first CSS with CSS-native configuration.1011## When to Use1213Use this skill when configuring Tailwind v4, using CSS-first theme and design tokens, or implementing container queries and modern Tailwind patterns.1415---1617## 1. Tailwind v4 Architecture1819### What Changed from v32021| v3 (Legacy) | v4 (Current) |22|-------------|--------------|23| `tailwind.config.js` | CSS-based `@theme` directive |24| PostCSS plugin | Oxide engine (10x faster) |25| JIT mode | Native, always-on |26| Plugin system | CSS-native features |27| `@apply` directive | Still works, discouraged |2829### v4 Core Concepts3031| Concept | Description |32|---------|-------------|33| **CSS-first** | Configuration in CSS, not JavaScript |34| **Oxide Engine** | Rust-based compiler, much faster |35| **Native Nesting** | CSS nesting without PostCSS |36| **CSS Variables** | All tokens exposed as `--*` vars |3738---3940## 2. CSS-Based Configuration4142### Theme Definition4344```45@theme {46 /* Colors - use semantic names */47 --color-primary: oklch(0.7 0.15 250);48 --color-surface: oklch(0.98 0 0);49 --color-surface-dark: oklch(0.15 0 0);50 51 /* Spacing scale */52 --spacing-xs: 0.25rem;53 --spacing-sm: 0.5rem;54 --spacing-md: 1rem;55 --spacing-lg: 2rem;56 57 /* Typography */58 --font-sans: 'Inter', system-ui, sans-serif;59 --font-mono: 'JetBrains Mono', monospace;60}61```6263### When to Extend vs Override6465| Action | Use When |66|--------|----------|67| **Extend** | Adding new values alongside defaults |68| **Override** | Replacing default scale entirely |69| **Semantic tokens** | Project-specific naming (primary, surface) |7071---7273## 3. Container Queries (v4 Native)7475### Breakpoint vs Container7677| Type | Responds To |78|------|-------------|79| **Breakpoint** (`md:`) | Viewport width |80| **Container** (`@container`) | Parent element width |8182### Container Query Usage8384| Pattern | Classes |85|---------|---------|86| Define container | `@container` on parent |87| Container breakpoint | `@sm:`, `@md:`, `@lg:` on children |88| Named containers | `@container/card` for specificity |8990### When to Use9192| Scenario | Use |93|----------|-----|94| Page-level layouts | Viewport breakpoints |95| Component-level responsive | Container queries |96| Reusable components | Container queries (context-independent) |9798---99100## 4. Responsive Design101102### Breakpoint System103104| Prefix | Min Width | Target |105|--------|-----------|--------|106| (none) | 0px | Mobile-first base |107| `sm:` | 640px | Large phone / small tablet |108| `md:` | 768px | Tablet |109| `lg:` | 1024px | Laptop |110| `xl:` | 1280px | Desktop |111| `2xl:` | 1536px | Large desktop |112113### Mobile-First Principle1141151. Write mobile styles first (no prefix)1162. Add larger screen overrides with prefixes1173. Example: `w-full md:w-1/2 lg:w-1/3`118119---120121## 5. Dark Mode122123### Configuration Strategies124125| Method | Behavior | Use When |126|--------|----------|----------|127| `class` | `.dark` class toggles | Manual theme switcher |128| `media` | Follows system preference | No user control |129| `selector` | Custom selector (v4) | Complex theming |130131### Dark Mode Pattern132133| Element | Light | Dark |134|---------|-------|------|135| Background | `bg-white` | `dark:bg-zinc-900` |136| Text | `text-zinc-900` | `dark:text-zinc-100` |137| Borders | `border-zinc-200` | `dark:border-zinc-700` |138139---140141## 6. Modern Layout Patterns142143### Flexbox Patterns144145| Pattern | Classes |146|---------|---------|147| Center (both axes) | `flex items-center justify-center` |148| Vertical stack | `flex flex-col gap-4` |149| Horizontal row | `flex gap-4` |150| Space between | `flex justify-between items-center` |151| Wrap grid | `flex flex-wrap gap-4` |152153### Grid Patterns154155| Pattern | Classes |156|---------|---------|157| Auto-fit responsive | `grid grid-cols-[repeat(auto-fit,minmax(250px,1fr))]` |158| Asymmetric (Bento) | `grid grid-cols-3 grid-rows-2` with spans |159| Sidebar layout | `grid grid-cols-[auto_1fr]` |160161> **Note:** Prefer asymmetric/Bento layouts over symmetric 3-column grids.162163---164165## 7. Modern Color System166167### OKLCH vs RGB/HSL168169| Format | Advantage |170|--------|-----------|171| **OKLCH** | Perceptually uniform, better for design |172| **HSL** | Intuitive hue/saturation |173| **RGB** | Legacy compatibility |174175### Color Token Architecture176177| Layer | Example | Purpose |178|-------|---------|---------|179| **Primitive** | `--blue-500` | Raw color values |180| **Semantic** | `--color-primary` | Purpose-based naming |181| **Component** | `--button-bg` | Component-specific |182183---184185## 8. Typography System186187### Font Stack Pattern188189| Type | Recommended |190|------|-------------|191| Sans | `'Inter', 'SF Pro', system-ui, sans-serif` |192| Mono | `'JetBrains Mono', 'Fira Code', monospace` |193| Display | `'Outfit', 'Poppins', sans-serif` |194195### Type Scale196197| Class | Size | Use |198|-------|------|-----|199| `text-xs` | 0.75rem | Labels, captions |200| `text-sm` | 0.875rem | Secondary text |201| `text-base` | 1rem | Body text |202| `text-lg` | 1.125rem | Lead text |203| `text-xl`+ | 1.25rem+ | Headings |204205---206207## 9. Animation &