tlq5l

tailwindcss-v4

2
0
# Install this skill:
npx skills add tlq5l/tailwindcss-v4-skill

Or install specific skill: npx add-skill https://github.com/tlq5l/tailwindcss-v4-skill

# Description

Tailwind CSS v4 patterns: CSS-first config, @theme/@utility/@variant directives, migration from v3. Use when working with Tailwind v4 projects.

# SKILL.md


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 theme
  • inline: Emit variables to output
  • static: Use values but don't emit vars
  • reference: 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

# README.md

Tailwind CSS v4 Skill

Inspired by Vercel's agent-skills

AI-agent skill for Tailwind CSS v4 patterns, migration, and best practices.

What is this?

A skill file that teaches AI coding agents (Claude, Copilot, Cursor, etc.) the correct patterns for Tailwind CSS v4. Agents read AGENTS.md and apply the knowledge when helping with Tailwind code.

Quick Start

  1. Copy AGENTS.md to your project root (or .claude/ for Claude Code)
  2. Your AI agent will automatically pick up the v4 patterns

Structure

tailwindcss-v4/
├── AGENTS.md           # Compiled skill (agents read this)
├── rules/              # Modular rule files
│   ├── setup-*.md      # Configuration patterns
│   ├── migration-*.md  # v3 → v4 migration
│   └── customization-*.md  # Custom utilities/variants
├── test-cases.json     # Bad/good code pairs for testing
└── src/
    ├── build.ts        # Compiles rules → AGENTS.md
    └── validate.ts     # CLI validation tests

Key v4 Patterns

Entry Point

/* v4 - single import */
@import "tailwindcss";

/* NOT the v3 way */
@tailwind base;
@tailwind components;
@tailwind utilities;

Theme Configuration

@theme {
  --color-primary: #3b82f6;
  --font-display: "Inter", sans-serif;
}

Custom Utilities

@utility content-auto {
  content-visibility: auto;
}

Custom Variants

@variant hocus (&:hover, &:focus);

Safelisting

@source inline("bg-red-500 text-white");

Development

# Build AGENTS.md from rules
bun run build

# Run validation
bun run validate

Contributing

  1. Add/edit rules in rules/*.md
  2. Add test cases to test-cases.json
  3. Run bun run build
  4. Submit PR

License

MIT

# Supported AI Coding Agents

This skill is compatible with the SKILL.md standard and works with all major AI coding agents:

Learn more about the SKILL.md standard and how to use these skills with your preferred AI coding agent.