code-architecture-tailwind-v4-best-practices

Guides Tailwind CSS v4 component styling patterns using utilities, CVA, and tailwind-variants.

Updated Apr 29, 2026
One-click install
npx skills add https://github.com/dev-khoi/AURA-conHack-2026 --skill code-architecture-tailwind-v4-best-practices-dev-khoi
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/dev-khoi/AURA-conHack-2026/tree/main/.opencode/skills/code-architecture-tailwind-v4-best-practices
Command: npx skills add https://github.com/dev-khoi/AURA-conHack-2026 --skill code-architecture-tailwind-v4-best-practices-dev-khoi

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Developers working with Tailwind CSS v4 face uncertainty about when to use raw utility classes versus abstraction libraries like CVA or tailwind-variants, and how to adapt to v4's CSS-first configuration model that replaces tailwind.config.js. ## Core Features & Use Cases - Decision Framework: Provides a clear rule for choosing between pure utilities (1-2 variants), CVA (3+ variants, ~1KB), and tailwind-variants (slots, responsive variants, ~4KB). - CSS-First Configuration: Explains the @theme directive for design tokens, @custom-variant for state selectors, and data-attribute-based state management. - Migration Guidance: Documents breaking changes from v3 to v4 (e.g., shadow-sm to shadow-xs, bg-gradient-to-r to bg-linear-to-r) and the automated upgrade tool. - Use Case: When building a React button component with multiple variants and sizes, follow the shadcn/ui-style pattern using tailwind-variants with proper accessibility attributes. ## Quick Start Ask the AI to create a React button component with primary, secondary, and outline variants following 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 instead of plain Tailwind utility classes?▼

Use CVA when a component has 3 or more variants and you need type safety, such as in component libraries. For components with only 1-2 variants or prototypes, plain utility classes are preferred since they add zero bundle overhead.

What is the difference between CVA and tailwind-variants?▼

CVA (~1KB) handles single-element variant styling with type safety, while tailwind-variants (~4KB) adds support for multi-part slot components, responsive variants, and component composition via extend. Choose tailwind-variants for complex design systems like cards or accordions.

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

Tailwind v4 uses CSS-first configuration through the @theme directive in your stylesheet. Define tokens like --color-brand-primary inside @theme, which generates both utility classes and CSS variables automatically after a single @import "tailwindcss" statement.

Is @apply still recommended in Tailwind CSS v4?▼

No, the Tailwind team discourages @apply for component styles because it hides styling decisions and breaks variant support. Use component abstractions like CVA instead, or the @utility directive only when a custom utility is genuinely needed.

What breaking changes should I watch for when migrating from Tailwind v3 to v4?▼

Key changes include shadow-sm becoming shadow-xs, rounded-sm becoming rounded-xs, bg-gradient-to-r becoming bg-linear-to-r, and default border color changing from gray-200 to currentColor. Run npx @tailwindcss/upgrade for automated migration.