1---2name: tailwind-patterns3description: Tailwind CSS v4 principles. CSS-first configuration, container queries,4 modern patterns, design token architecture.5allowed-tools: Read, Write, Edit, Glob, Grep6risk: safe7source: community8license: MIT9metadata:10 source: https://skillmd.com/skills/jantoniofc/tailwind-patterns11---1213# Tailwind CSS Patterns (v4 - 2025)1415> Modern utility-first CSS with CSS-native configuration.1617---1819## 1. Tailwind v4 Architecture2021### What Changed from v32223| v3 (Legacy) | v4 (Current) |24|-------------|--------------|25| `tailwind.config.js` | CSS-based `@theme` directive |26| PostCSS plugin | Oxide engine (10x faster) |27| JIT mode | Native, always-on |28| Plugin system | CSS-native features |29| `@apply` directive | Still works, discouraged |3031### v4 Core Concepts3233| Concept | Description |34|---------|-------------|35| **CSS-first** | Configuration in CSS, not JavaScript |36| **Oxide Engine** | Rust-based compiler, much faster |37| **Native Nesting** | CSS nesting without PostCSS |38| **CSS Variables** | All tokens exposed as `--*` vars |3940---4142## 2. CSS-Based Configuration4344### Theme Definition4546```47@theme {48 /* Colors - use semantic names */49 --color-primary: oklch(0.7 0.15 250);50 --color-surface: oklch(0.98 0 0);51 --color-surface-dark: oklch(0.15 0 0);52 53 /* Spacing scale */54 --spacing-xs: 0.25rem;55 --spacing-sm: 0.5rem;56 --spacing-md: 1rem;57 --spacing-lg: 2rem;58 59 /* Typography */60 --font-sans: 'Inter', system-ui, sans-serif;61 --font-mono: 'JetBrains Mono', monospace;62}63```6465### When to Extend vs Override6667| Action | Use When |68|--------|----------|69| **Extend** | Adding new values alongside defaults |70| **Override** | Replacing default scale entirely |71| **Semantic tokens** | Project-specific naming (primary, surface) |7273---7475## 3. Container Queries (v4 Native)7677### Breakpoint vs Container7879| Type | Responds To |80|------|-------------|81| **Breakpoint** (`md:`) | Viewport width |82| **Container** (`@container`) | Parent element width |8384### Container Query Usage8586| Pattern | Classes |87|---------|---------|88| Define container | `@container` on parent |89| Container breakpoint | `@sm:`, `@md:`, `@lg:` on children |90| Named containers | `@container/card` for specificity |9192### When to Use9394| Scenario | Use |95|----------|-----|96| Page-level layouts | Viewport breakpoints |97| Component-level responsive | Container queries |98| Reusable components | Container queries (context-independent) |99100---101102## 4. Responsive Design103104### Breakpoint System105106| Prefix | Min Width | Target |107|--------|-----------|--------|108| (none) | 0px | Mobile-first base |109| `sm:` | 640px | Large phone / small tablet |110| `md:` | 768px | Tablet |111| `lg:` | 1024px | Laptop |112| `xl:` | 1280px | Desktop |113| `2xl:` | 1536px | Large desktop |114115### Mobile-First Principle1161171. Write mobile styles first (no prefix)1182. Add larger screen overrides with prefixes1193. Example: `w-full md:w-1/2 lg:w-1/3`120121---122123## 5. Dark Mode124125### Configuration Strategies126127| Method | Behavior | Use When |128|--------|----------|----------|129| `class` | `.dark` class toggles | Manual theme switcher |130| `media` | Follows system preference | No user control |131| `selector` | Custom selector (v4) | Complex theming |132133### Dark Mode Pattern134135| Element | Light | Dark |136|---------|-------|------|137| Background | `bg-white` | `dark:bg-zinc-900` |138| Text | `text-zinc-900` | `dark:text-zinc-100` |139| Borders | `border-zinc-200` | `dark:border-zinc-700` |140141---142143## 6. Modern Layout Patterns144145### Flexbox Patterns146147| Pattern | Classes |148|---------|---------|149| Center (both axes) | `flex items-center justify-center` |150| Vertical stack | `flex flex-col gap-4` |151| Horizontal row | `flex gap-4` |152| Space between | `flex justify-between items-center` |153| Wrap grid | `flex flex-wrap gap-4` |154155### Grid Patterns156157| Pattern | Classes |158|---------|---------|159| Auto-fit responsive | `grid grid-cols-[repeat(auto-fit,minmax(250px,1fr))]` |160| Asymmetric (Bento) | `grid grid-cols-3 grid-rows-2` with spans |161| Sidebar layout | `grid grid-cols-[auto_1fr]` |162163> **Note:** Prefer asymmetric/Bento layouts over symmetric 3-column grids.164165---166167## 7. Modern Color System168169### OKLCH vs RGB/HSL170171| Format | Advantage |172|--------|-----------|173| **OKLCH** | Perceptually uniform, better for design |174| **HSL** | Intuitive hue/saturation |175| **RGB** | Legacy compatibility |176177### Color Token Architecture178179| Layer | Example | Purpose |180|-------|---------|---------|181| **Primitive** | `--blue-500` | Raw color values |182| **Semantic** | `--color-primary` | Purpose-based naming |183| **Component** | `--button-bg` | Component-specific |184185---186187## 8. Typography System188189### Font Stack Pattern190191| Type | Recommended |192|------|-------------|193| Sans | `'Inter', 'SF Pro', system-ui, sans-serif` |194| Mono | `'JetBrains Mono', 'Fira Code', monospace` |195| Display | `'Outfit', 'Poppins', sans-serif` |196197### Type Scale198199| Class | Size | Use |200|-------|------|-----|201| `text-xs` | 0.75rem | Labels, captions |202| `text-sm` | 0.875rem | Secondary text |203| `text-base` | 1rem | Body text |204| `text-lg` | 1.125rem | Lead text |205| `text-xl`+ | 1.25rem+ | Headings |206207---208209## 9. Animation & Transitions210211### Built-in Animations212213| Class | Effect |214|-------|--------|215| `animate-spin` | Continuous rotation |216| `animate-ping` | Attention pulse |217| `animate-pulse` | Subtle opacity pulse |218| `animate-bounce` | Bouncing effect |219220### Transition Patterns221222| Pattern | Classes |223|---------|---------|224| All properties | `transition-all duration-200` |225| Specific | `transition-colors duration-150` |226| With easing | `ease-out` or `ease-in-out` |227| Hover effect | `hover:scale-105 transition-transform` |228229---230231## 10. Component Extraction232233### When to Extract234235| Signal | Action |236|--------|--------|237| Same class combo 3+ times | Extract component |238| Complex state variants | Extract component |239| Design system element | Extract + document |240241### Extraction Methods242243| Method | Use When |244|--------|----------|245| **React/Vue component** | Dynamic, JS needed |246| **@apply in CSS** | Static, no JS needed |247| **Design tokens** | Reusable values |248249---250251## 11. Anti-Patterns252253| Don't | Do |254|-------|-----|255| Arbitrary values everywhere | Use design system scale |256| `!important` | Fix specificity properly |257| Inline `style=` | Use utilities |258| Duplicate long class lists | Extract component |259| Mix v3 config with v4 | Migrate fully to CSS-first |260| Use `@apply` heavily | Prefer components |261262---263264## 12. Performance Principles265266| Principle | Implementation |267|-----------|----------------|268| **Purge unused** | Automatic in v4 |269| **Avoid dynamism** | No template string classes |270| **Use Oxide** | Default in v4, 10x faster |271| **Cache builds** | CI/CD caching |272273---274275> **Remember:** Tailwind v4 is CSS-first. Embrace CSS variables, container queries, and native features. The config file is now optional.276277## Limitations278- Use this skill only when the task clearly matches the scope described above.279- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.280- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.