name: tailwind-patterns
description: Tailwind CSS v4 patterns covering CSS-first configuration, container queries, OKLCH color systems, responsive design, and modern layout patterns. Use when configuring Tailwind v4, implementing design tokens, or building responsive utility-first CSS layouts.
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 & Transitions
Built-in Animations
| Class |
Effect |
animate-spin |
Continuous rotation |
animate-ping |
Attention pulse |
animate-pulse |
Subtle opacity pulse |
animate-bounce |
Bouncing effect |
Transition Patterns
| Pattern |
Classes |
| All properties |
transition-all duration-200 |
| Specific |
transition-colors duration-150 |
| With easing |
ease-out or ease-in-out |
| Hover effect |
hover:scale-105 transition-transform |
10. Component Extraction
When to Extract
| Signal |
Action |
| Same class combo 3+ times |
Extract component |
| Complex state variants |
Extract component |
| Design system element |
Extract + document |
Extraction Methods
| Method |
Use When |
| React/Vue component |
Dynamic, JS needed |
| @apply in CSS |
Static, no JS needed |
| Design tokens |
Reusable values |
11. Anti-Patterns
| Don't |
Do |
| Arbitrary values everywhere |
Use design system scale |
!important |
Fix specificity properly |
Inline style= |
Use utilities |
| Duplicate long class lists |
Extract component |
| Mix v3 config with v4 |
Migrate fully to CSS-first |
Use @apply heavily |
Prefer components |
12. Performance Principles
| Principle |
Implementation |
| Purge unused |
Automatic in v4 |
| Avoid dynamism |
No template string classes |
| Use Oxide |
Default in v4, 10x faster |
| Cache builds |
CI/CD caching |
Remember: Tailwind v4 is CSS-first. Embrace CSS variables, container queries, and native features. The config file is now optional.
1---2name: tailwind-patterns-33description: <!-- AUTO-GENERATED by export-skills.py — DO NOT EDIT -->4---5<!-- AUTO-GENERATED by export-skills.py — DO NOT EDIT -->6---7name: tailwind-patterns8description: Tailwind CSS v4 patterns covering CSS-first configuration, container queries, OKLCH color systems, responsive design, and modern layout patterns. Use when configuring Tailwind v4, implementing design tokens, or building responsive utility-first CSS layouts.9---1011# Tailwind CSS Patterns (v4 - 2025)1213> Modern utility-first CSS with CSS-native configuration.1415## When to Use1617Use this skill when configuring Tailwind v4, using CSS-first theme and design tokens, or implementing container queries and modern Tailwind patterns.1819---2021## 1. Tailwind v4 Architecture2223### What Changed from v32425| v3 (Legacy) | v4 (Current) |26|-------------|--------------|27| `tailwind.config.js` | CSS-based `@theme` directive |28| PostCSS plugin | Oxide engine (10x faster) |29| JIT mode | Native, always-on |30| Plugin system | CSS-native features |31| `@apply` directive | Still works, discouraged |3233### v4 Core Concepts3435| Concept | Description |36|---------|-------------|37| **CSS-first** | Configuration in CSS, not JavaScript |38| **Oxide Engine** | Rust-based compiler, much faster |39| **Native Nesting** | CSS nesting without PostCSS |40| **CSS Variables** | All tokens exposed as `--*` vars |4142---4344## 2. CSS-Based Configuration4546### Theme Definition4748```49@theme {50 /* Colors - use semantic names */51 --color-primary: oklch(0.7 0.15 250);52 --color-surface: oklch(0.98 0 0);53 --color-surface-dark: oklch(0.15 0 0);5455 /* Spacing scale */56 --spacing-xs: 0.25rem;57 --spacing-sm: 0.5rem;58 --spacing-md: 1rem;59 --spacing-lg: 2rem;6061 /* Typography */62 --font-sans: 'Inter', system-ui, sans-serif;63 --font-mono: 'JetBrains Mono', monospace;64}65```6667### When to Extend vs Override6869| Action | Use When |70|--------|----------|71| **Extend** | Adding new values alongside defaults |72| **Override** | Replacing default scale entirely |73| **Semantic tokens** | Project-specific naming (primary, surface) |7475---7677## 3. Container Queries (v4 Native)7879### Breakpoint vs Container8081| Type | Responds To |82|------|-------------|83| **Breakpoint** (`md:`) | Viewport width |84| **Container** (`@container`) | Parent element width |8586### Container Query Usage8788| Pattern | Classes |89|---------|---------|90| Define container | `@container` on parent |91| Container breakpoint | `@sm:`, `@md:`, `@lg:` on children |92| Named containers | `@container/card` for specificity |9394### When to Use9596| Scenario | Use |97|----------|-----|98| Page-level layouts | Viewport breakpoints |99| Component-level responsive | Container queries |100| Reusable components | Container queries (context-independent) |101102---103104## 4. Responsive Design105106### Breakpoint System107108| Prefix | Min Width | Target |109|--------|-----------|--------|110| (none) | 0px | Mobile-first base |111| `sm:` | 640px | Large phone / small tablet |112| `md:` | 768px | Tablet |113| `lg:` | 1024px | Laptop |114| `xl:` | 1280px | Desktop |115| `2xl:` | 1536px | Large desktop |116117### Mobile-First Principle1181191. Write mobile styles first (no prefix)1202. Add larger screen overrides with prefixes1213. Example: `w-full md:w-1/2 lg:w-1/3`122123---124125## 5. Dark Mode126127### Configuration Strategies128129| Method | Behavior | Use When |130|--------|----------|----------|131| `class` | `.dark` class toggles | Manual theme switcher |132| `media` | Follows system preference | No user control |133| `selector` | Custom selector (v4) | Complex theming |134135### Dark Mode Pattern136137| Element | Light | Dark |138|---------|-------|------|139| Background | `bg-white` | `dark:bg-zinc-900` |140| Text | `text-zinc-900` | `dark:text-zinc-100` |141| Borders | `border-zinc-200` | `dark:border-zinc-700` |142143---144145## 6. Modern Layout Patterns146147### Flexbox Patterns148149| Pattern | Classes |150|---------|---------|151| Center (both axes) | `flex items-center justify-center` |152| Vertical stack | `flex flex-col gap-4` |153| Horizontal row | `flex gap-4` |154| Space between | `flex justify-between items-center` |155| Wrap grid | `flex flex-wrap gap-4` |156157### Grid Patterns158159| Pattern | Classes |160|---------|---------|161| Auto-fit responsive | `grid grid-cols-[repeat(auto-fit,minmax(250px,1fr))]` |162| Asymmetric (Bento) | `grid grid-cols-3 grid-rows-2` with spans |163| Sidebar layout | `grid grid-cols-[auto_1fr]` |164165> **Note:** Prefer asymmetric/Bento layouts over symmetric 3-column grids.166167---168169## 7. Modern Color System170171### OKLCH vs RGB/HSL172173| Format | Advantage |174|--------|-----------|175| **OKLCH** | Perceptually uniform, better for design |176| **HSL** | Intuitive hue/saturation |177| **RGB** | Legacy compatibility |178179### Color Token Architecture180181| Layer | Example | Purpose |182|-------|---------|---------|183| **Primitive** | `--blue-500` | Raw color values |184| **Semantic** | `--color-primary` | Purpose-based naming |185| **Component** | `--button-bg` | Component-specific |186187---188189## 8. Typography System190191### Font Stack Pattern192193| Type | Recommended |194|------|-------------|195| Sans | `'Inter', 'SF Pro', system-ui, sans-serif` |196| Mono | `'JetBrains Mono', 'Fira Code', monospace` |197| Display | `'Outfit', 'Poppins', sans-serif` |198199### Type Scale200201| Class | Size | Use |202|-------|------|-----|203| `text-xs` | 0.75rem | Labels, captions |204| `text-sm` | 0.875rem | Secondary text |205| `text-base` | 1rem | Body text |206| `text-lg` | 1.125rem | Lead text |207| `text-xl`+ | 1.25rem+ | Headings |208209---210211## 9. Animation & Transitions212213### Built-in Animations214215| Class | Effect |216|-------|--------|217| `animate-spin` | Continuous rotation |218| `animate-ping` | Attention pulse |219| `animate-pulse` | Subtle opacity pulse |220| `animate-bounce` | Bouncing effect |221222### Transition Patterns223224| Pattern | Classes |225|---------|---------|226| All properties | `transition-all duration-200` |227| Specific | `transition-colors duration-150` |228| With easing | `ease-out` or `ease-in-out` |229| Hover effect | `hover:scale-105 transition-transform` |230231---232233## 10. Component Extraction234235### When to Extract236237| Signal | Action |238|--------|--------|239| Same class combo 3+ times | Extract component |240| Complex state variants | Extract component |241| Design system element | Extract + document |242243### Extraction Methods244245| Method | Use When |246|--------|----------|247| **React/Vue component** | Dynamic, JS needed |248| **@apply in CSS** | Static, no JS needed |249| **Design tokens** | Reusable values |250251---252253## 11. Anti-Patterns254255| Don't | Do |256|-------|-----|257| Arbitrary values everywhere | Use design system scale |258| `!important` | Fix specificity properly |259| Inline `style=` | Use utilities |260| Duplicate long class lists | Extract component |261| Mix v3 config with v4 | Migrate fully to CSS-first |262| Use `@apply` heavily | Prefer components |263264---265266## 12. Performance Principles267268| Principle | Implementation |269|-----------|----------------|270| **Purge unused** | Automatic in v4 |271| **Avoid dynamism** | No template string classes |272| **Use Oxide** | Default in v4, 10x faster |273| **Cache builds** | CI/CD caching |274275---276277> **Remember:** Tailwind v4 is CSS-first. Embrace CSS variables, container queries, and native features. The config file is now optional.278279<!-- Source: .faos/custom/skills/frontend/tailwind-patterns/SKILL.md -->