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.
Limitations
- Use this skill only when the task clearly matches the scope described above.
- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.
1---2name: tailwind-patterns3description: Tailwind CSS v4 principles. CSS-first configuration, container queries, modern patterns, design token architecture.4metadata:5 source: https://skillmd.com/skills/gabrielmoreira/tailwind-patterns6 aas-risk: none7 aas-source: community8 aas-date-added: '2026-02-27'9---1011# Tailwind CSS Patterns (v4 - 2025)1213> Modern utility-first CSS with CSS-native configuration.1415## When to Use16Use this skill when configuring Tailwind v4, using CSS-first theme and design tokens, or implementing container queries and modern Tailwind patterns.1718---1920## 1. Tailwind v4 Architecture2122### What Changed from v32324| v3 (Legacy) | v4 (Current) |25|-------------|--------------|26| `tailwind.config.js` | CSS-based `@theme` directive |27| PostCSS plugin | Oxide engine (10x faster) |28| JIT mode | Native, always-on |29| Plugin system | CSS-native features |30| `@apply` directive | Still works, discouraged |3132### v4 Core Concepts3334| Concept | Description |35|---------|-------------|36| **CSS-first** | Configuration in CSS, not JavaScript |37| **Oxide Engine** | Rust-based compiler, much faster |38| **Native Nesting** | CSS nesting without PostCSS |39| **CSS Variables** | All tokens exposed as `--*` vars |4041---4243## 2. CSS-Based Configuration4445### Theme Definition4647```48@theme {49 /* Colors - use semantic names */50 --color-primary: oklch(0.7 0.15 250);51 --color-surface: oklch(0.98 0 0);52 --color-surface-dark: oklch(0.15 0 0);53 54 /* Spacing scale */55 --spacing-xs: 0.25rem;56 --spacing-sm: 0.5rem;57 --spacing-md: 1rem;58 --spacing-lg: 2rem;59 60 /* Typography */61 --font-sans: 'Inter', system-ui, sans-serif;62 --font-mono: 'JetBrains Mono', monospace;63}64```6566### When to Extend vs Override6768| Action | Use When |69|--------|----------|70| **Extend** | Adding new values alongside defaults |71| **Override** | Replacing default scale entirely |72| **Semantic tokens** | Project-specific naming (primary, surface) |7374---7576## 3. Container Queries (v4 Native)7778### Breakpoint vs Container7980| Type | Responds To |81|------|-------------|82| **Breakpoint** (`md:`) | Viewport width |83| **Container** (`@container`) | Parent element width |8485### Container Query Usage8687| Pattern | Classes |88|---------|---------|89| Define container | `@container` on parent |90| Container breakpoint | `@sm:`, `@md:`, `@lg:` on children |91| Named containers | `@container/card` for specificity |9293### When to Use9495| Scenario | Use |96|----------|-----|97| Page-level layouts | Viewport breakpoints |98| Component-level responsive | Container queries |99| Reusable components | Container queries (context-independent) |100101---102103## 4. Responsive Design104105### Breakpoint System106107| Prefix | Min Width | Target |108|--------|-----------|--------|109| (none) | 0px | Mobile-first base |110| `sm:` | 640px | Large phone / small tablet |111| `md:` | 768px | Tablet |112| `lg:` | 1024px | Laptop |113| `xl:` | 1280px | Desktop |114| `2xl:` | 1536px | Large desktop |115116### Mobile-First Principle1171181. Write mobile styles first (no prefix)1192. Add larger screen overrides with prefixes1203. Example: `w-full md:w-1/2 lg:w-1/3`121122---123124## 5. Dark Mode125126### Configuration Strategies127128| Method | Behavior | Use When |129|--------|----------|----------|130| `class` | `.dark` class toggles | Manual theme switcher |131| `media` | Follows system preference | No user control |132| `selector` | Custom selector (v4) | Complex theming |133134### Dark Mode Pattern135136| Element | Light | Dark |137|---------|-------|------|138| Background | `bg-white` | `dark:bg-zinc-900` |139| Text | `text-zinc-900` | `dark:text-zinc-100` |140| Borders | `border-zinc-200` | `dark:border-zinc-700` |141142---143144## 6. Modern Layout Patterns145146### Flexbox Patterns147148| Pattern | Classes |149|---------|---------|150| Center (both axes) | `flex items-center justify-center` |151| Vertical stack | `flex flex-col gap-4` |152| Horizontal row | `flex gap-4` |153| Space between | `flex justify-between items-center` |154| Wrap grid | `flex flex-wrap gap-4` |155156### Grid Patterns157158| Pattern | Classes |159|---------|---------|160| Auto-fit responsive | `grid grid-cols-[repeat(auto-fit,minmax(250px,1fr))]` |161| Asymmetric (Bento) | `grid grid-cols-3 grid-rows-2` with spans |162| Sidebar layout | `grid grid-cols-[auto_1fr]` |163164> **Note:** Prefer asymmetric/Bento layouts over symmetric 3-column grids.165166---167168## 7. Modern Color System169170### OKLCH vs RGB/HSL171172| Format | Advantage |173|--------|-----------|174| **OKLCH** | Perceptually uniform, better for design |175| **HSL** | Intuitive hue/saturation |176| **RGB** | Legacy compatibility |177178### Color Token Architecture179180| Layer | Example | Purpose |181|-------|---------|---------|182| **Primitive** | `--blue-500` | Raw color values |183| **Semantic** | `--color-primary` | Purpose-based naming |184| **Component** | `--button-bg` | Component-specific |185186---187188## 8. Typography System189190### Font Stack Pattern191192| Type | Recommended |193|------|-------------|194| Sans | `'Inter', 'SF Pro', system-ui, sans-serif` |195| Mono | `'JetBrains Mono', 'Fira Code', monospace` |196| Display | `'Outfit', 'Poppins', sans-serif` |197198### Type Scale199200| Class | Size | Use |201|-------|------|-----|202| `text-xs` | 0.75rem | Labels, captions |203| `text-sm` | 0.875rem | Secondary text |204| `text-base` | 1rem | Body text |205| `text-lg` | 1.125rem | Lead text |206| `text-xl`+ | 1.25rem+ | Headings |207208---209210## 9. Animation & Transitions211212### Built-in Animations213214| Class | Effect |215|-------|--------|216| `animate-spin` | Continuous rotation |217| `animate-ping` | Attention pulse |218| `animate-pulse` | Subtle opacity pulse |219| `animate-bounce` | Bouncing effect |220221### Transition Patterns222223| Pattern | Classes |224|---------|---------|225| All properties | `transition-all duration-200` |226| Specific | `transition-colors duration-150` |227| With easing | `ease-out` or `ease-in-out` |228| Hover effect | `hover:scale-105 transition-transform` |229230---231232## 10. Component Extraction233234### When to Extract235236| Signal | Action |237|--------|--------|238| Same class combo 3+ times | Extract component |239| Complex state variants | Extract component |240| Design system element | Extract + document |241242### Extraction Methods243244| Method | Use When |245|--------|----------|246| **React/Vue component** | Dynamic, JS needed |247| **@apply in CSS** | Static, no JS needed |248| **Design tokens** | Reusable values |249250---251252## 11. Anti-Patterns253254| Don't | Do |255|-------|-----|256| Arbitrary values everywhere | Use design system scale |257| `!important` | Fix specificity properly |258| Inline `style=` | Use utilities |259| Duplicate long class lists | Extract component |260| Mix v3 config with v4 | Migrate fully to CSS-first |261| Use `@apply` heavily | Prefer components |262263---264265## 12. Performance Principles266267| Principle | Implementation |268|-----------|----------------|269| **Purge unused** | Automatic in v4 |270| **Avoid dynamism** | No template string classes |271| **Use Oxide** | Default in v4, 10x faster |272| **Cache builds** | CI/CD caching |273274---275276> **Remember:** Tailwind v4 is CSS-first. Embrace CSS variables, container queries, and native features. The config file is now optional.277278## Limitations279- Use this skill only when the task clearly matches the scope described above.280- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.281- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.