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-patterns
3description: "Tailwind CSS v4 principles. CSS-first configuration, container queries, modern patterns, design token architecture."
4risk: unknown
5source: community
6date_added: "2026-02-27"
7metadata:
8 source: https://skillmd.com/skills/bouclem/tailwind-patterns
9---
10
11# Tailwind CSS Patterns (v4 - 2025)
12
13> Modern utility-first CSS with CSS-native configuration.
14
15## When to Use
16Use this skill when configuring Tailwind v4, using CSS-first theme and design tokens, or implementing container queries and modern Tailwind patterns.
17
18---
19
20## 1. Tailwind v4 Architecture
21
22### What Changed from v3
23
24| 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 |
31
32### v4 Core Concepts
33
34| 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 |
40
41---
42
43## 2. CSS-Based Configuration
44
45### Theme Definition
46
47```
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```
65
66### When to Extend vs Override
67
68| 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) |
73
74---
75
76## 3. Container Queries (v4 Native)
77
78### Breakpoint vs Container
79
80| Type | Responds To |
81|------|-------------|
82| **Breakpoint** (`md:`) | Viewport width |
83| **Container** (`@container`) | Parent element width |
84
85### Container Query Usage
86
87| Pattern | Classes |
88|---------|---------|
89| Define container | `@container` on parent |
90| Container breakpoint | `@sm:`, `@md:`, `@lg:` on children |
91| Named containers | `@container/card` for specificity |
92
93### When to Use
94
95| Scenario | Use |
96|----------|-----|
97| Page-level layouts | Viewport breakpoints |
98| Component-level responsive | Container queries |
99| Reusable components | Container queries (context-independent) |
100
101---
102
103## 4. Responsive Design
104
105### Breakpoint System
106
107| 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 |
115
116### Mobile-First Principle
117
1181. Write mobile styles first (no prefix)
1192. Add larger screen overrides with prefixes
1203. Example: `w-full md:w-1/2 lg:w-1/3`
121
122---
123
124## 5. Dark Mode
125
126### Configuration Strategies
127
128| 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 |
133
134### Dark Mode Pattern
135
136| 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` |
141
142---
143
144## 6. Modern Layout Patterns
145
146### Flexbox Patterns
147
148| 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` |
155
156### Grid Patterns
157
158| 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]` |
163
164> **Note:** Prefer asymmetric/Bento layouts over symmetric 3-column grids.
165
166---
167
168## 7. Modern Color System
169
170### OKLCH vs RGB/HSL
171
172| Format | Advantage |
173|--------|-----------|
174| **OKLCH** | Perceptually uniform, better for design |
175| **HSL** | Intuitive hue/saturation |
176| **RGB** | Legacy compatibility |
177
178### Color Token Architecture
179
180| Layer | Example | Purpose |
181|-------|---------|---------|
182| **Primitive** | `--blue-500` | Raw color values |
183| **Semantic** | `--color-primary` | Purpose-based naming |
184| **Component** | `--button-bg` | Component-specific |
185
186---
187
188## 8. Typography System
189
190### Font Stack Pattern
191
192| 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` |
197
198### Type Scale
199
200| 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 |
207
208---
209
210## 9. Animation & Transitions
211
212### Built-in Animations
213
214| Class | Effect |
215|-------|--------|
216| `animate-spin` | Continuous rotation |
217| `animate-ping` | Attention pulse |
218| `animate-pulse` | Subtle opacity pulse |
219| `animate-bounce` | Bouncing effect |
220
221### Transition Patterns
222
223| 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` |
229
230---
231
232## 10. Component Extraction
233
234### When to Extract
235
236| Signal | Action |
237|--------|--------|
238| Same class combo 3+ times | Extract component |
239| Complex state variants | Extract component |
240| Design system element | Extract + document |
241
242### Extraction Methods
243
244| Method | Use When |
245|--------|----------|
246| **React/Vue component** | Dynamic, JS needed |
247| **@apply in CSS** | Static, no JS needed |
248| **Design tokens** | Reusable values |
249
250---
251
252## 11. Anti-Patterns
253
254| 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 |
262
263---
264
265## 12. Performance Principles
266
267| 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 |
273
274---
275
276> **Remember:** Tailwind v4 is CSS-first. Embrace CSS variables, container queries, and native features. The config file is now optional.
277
278## Limitations
279- 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.