code-architecture-tailwind-v4-best-practices

Guides Tailwind CSS v4 component patterns using CVA, tailwind-variants, and CSS-first configuration.

Updated Aug 16, 2026
One-click install
npx skills add https://github.com/Aveer/skills --skill code-architecture-tailwind-v4-best-practices-aveer
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: code-architecture-tailwind-v4-best-practices
Source: https://github.com/Aveer/skills/tree/main/skills/code-architecture-tailwind-v4-best-practices
Command: npx skills add https://github.com/Aveer/skills --skill code-architecture-tailwind-v4-best-practices-aveer

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Choosing how to structure Tailwind CSS v4 components is confusing: developers struggle to decide between pure utilities, CVA, or tailwind-variants, and often misuse @apply or miss v4's breaking changes from v3. ## Core Features & Use Cases - Decision Matrix: Provides clear rules for when to use pure utilities (1-2 variants), CVA (3+ variants, ~1KB), or tailwind-variants (slots, responsive variants, ~4KB). - CSS-First Configuration: Explains v4's @theme directive, @custom-variant, data-attribute state styling, and the removal of tailwind.config.js. - Migration Guidance: Lists breaking changes from v3 (e.g., shadow-sm to shadow-xs, bg-gradient-to-r to bg-linear-to-r) and the automated upgrade command. - Use Case: When building a React button component with multiple variants and sizes, follow the shadcn/ui-style pattern with tv() or cva() to get type-safe, accessible, and maintainable class composition. ## Quick Start Ask the AI to create a type-safe button component with primary, secondary, and outline variants using Tailwind CSS v4 best practices.

Frequently Asked Questions about code-architecture-tailwind-v4-best-practices

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
When should I use CVA vs tailwind-variants for Tailwind components?▼

Use CVA (~1KB) for components with 3+ variants needing type safety, such as buttons in a component library. Use tailwind-variants (~4KB) when you need responsive variants, multi-part slot components like cards, or composition via extend.

How do I configure Tailwind CSS v4 without tailwind.config.js?▼

Tailwind v4 uses CSS-first configuration: import with `@import "tailwindcss"` and define design tokens inside an `@theme` block, such as `--color-brand-primary`. These tokens generate utilities and expose CSS variables automatically.

Should I use @apply in Tailwind CSS v4?▼

No, the Tailwind team discourages @apply for component styles because it hides styling decisions and breaks variant support. Use utilities directly in markup, component abstractions like CVA, or @utility only for genuinely reusable custom utilities.

What breaking changes exist when migrating from Tailwind v3 to v4?▼

Key changes include `shadow-sm` becoming `shadow-xs`, `rounded-sm` becoming `rounded-xs`, `bg-opacity-50` replaced by `bg-black/50`, and `bg-gradient-to-r` renamed to `bg-linear-to-r`. Run `npx @tailwindcss/upgrade` for automated migration.

How do I handle component state styling in Tailwind v4?▼

Use native data attributes like `data-loading` and `data-disabled` on elements, then style them with variants such as `data-loading:opacity-50`. You can also define custom variants with `@custom-variant` for compound selectors.