💡 Summary
This skill provides CSS-first configuration and directives for Tailwind CSS v4, facilitating migration from v3.
🎯 Target Audience
🤖 AI Roast: “Powerful, but the setup might scare off the impatient.”
Risk: Medium. Review: outbound network access (SSRF, data egress). Run with least privilege and audit before enabling in production.
name: tailwindcss-v4 description: "Tailwind CSS v4 patterns: CSS-first config, @theme/@utility/@variant directives, migration from v3. Use when working with Tailwind v4 projects." proactive: match match:
- "tailwind"
- "tailwindcss"
- "@theme"
- "@utility"
- "@variant"
Tailwind CSS v4 Skill
CSS-first configuration, new directives, migration from v3.
Quick Reference
v4 Entry Point
@import "tailwindcss";
NOT the v3 way:
/* ❌ These cause errors in v4 */ @tailwind base; @tailwind components; @tailwind utilities;
Key Directives
| Directive | Purpose |
|-----------|---------|
| @theme | Define design tokens (colors, spacing, fonts) |
| @utility | Create custom utility classes |
| @variant | Define custom variants (hover, focus, etc.) |
| @source | Control class detection and safelisting |
| @reference | Import for @apply without emitting CSS |
Theme Configuration (CSS-first)
@import "tailwindcss"; @theme { --color-primary: #3b82f6; --color-secondary: #64748b; --font-display: "Inter", sans-serif; --spacing-18: 4.5rem; }
NOT tailwind.config.js:
// ❌ v3 pattern - don't use in v4 module.exports = { theme: { extend: { colors: { primary: '#3b82f6' } } } }
Custom Utilities
@utility content-auto { content-visibility: auto; } /* Functional utility must end in -* */ @utility tab-* { --tab-size: --value(--spacing-*, [integer]); tab-size: var(--tab-size); }
Custom Variants
Use @custom-variant to define new variants (not @variant).
@custom-variant hocus (&:hover, &:focus); /* Dark mode with class strategy */ @custom-variant dark (&:is(.dark *)); /* Body block with @slot */ @custom-variant hocus { &:hover, &:focus { @slot; } }
Theme Configuration
@theme { --color-primary: #3b82f6; /* Clear namespace */ --color-*: initial; }
Theme Flags
default: Merge with default themeinline: Emit variables to outputstatic: Use values but don't emit varsreference: Use values but don't emit CSS
@theme inline { --font-sans: "SF Pro Text", system-ui; }
New Gradient Syntax
<!-- v4 preferred - supports interpolation color space --> <div class="bg-linear-to-r/oklch from-blue-500 to-purple-500"></div> <!-- Also: bg-linear-to-b, bg-radial, bg-conic -->
New Variants
@min-[400px]:/@max-[600px]:(Container queries)starting:(@starting-style)details-content:(::details-content)inverted-colors:,noscript:,print:
Safelisting Classes
/* Inline safelist */ @source inline("bg-red-500 text-white hidden"); /* From external source */ @source "../content/**/*.md";
Migration from v3
| v3 | v4 |
|----|-----|
| @tailwind base/components/utilities | @import "tailwindcss" |
| tailwind.config.js theme.extend | @theme { --color-* } |
| PostCSS tailwindcss plugin | @tailwindcss/postcss |
| @apply with config values | @reference import first |
PostCSS Setup
// postcss.config.js export default { plugins: { '@tailwindcss/postcss': {} // NOT 'tailwindcss' } }
Vite Setup
// vite.config.ts import tailwindcss from '@tailwindcss/vite' export default { plugins: [tailwindcss()] }
Sources: Tailwind v4 Docs, GitHub
Pros
- Clear migration path from v3 to v4
- Supports CSS-first configuration
- Provides new utility and variant directives
Cons
- May require learning new syntax
- Migration could be complex for large projects
- Limited backward compatibility with v3
Related Skills
web-perf
A“This skill is so thorough it might start charging consulting fees after the audit.”
tldraw
A“A fantastic library for drawing, though its licensing model means your masterpiece will forever be signed 'Made with tldraw' unless you pay the ransom.”
Disclaimer: This content is sourced from GitHub open source projects for display and rating purposes only.
Copyright belongs to the original author tlq5l.
