Use Tailwind utilities first. Abstract only when variants justify it.
When to Use
- Building Tailwind v4 components.
- Choosing utilities, CVA, or tailwind-variants.
- Creating button or card variants.
- Setting Tailwind v4 theme tokens.
- Migrating Tailwind v3 patterns.
Goal
Keep styling local, explicit, accessible, and easy to change.
Rules
- Use utility classes directly for simple components.
- Use CVA when a component has 3+ variants and needs type-safe props.
- Use tailwind-variants for slots, compound parts, or complex design systems.
- Avoid
@applyfor component styles. - Use
@themefor design tokens. - Use data attributes for component state.
- Keep one styling approach per component family.
- Preserve accessibility on interactive elements.
Tailwind v4 Setup
@import "tailwindcss";
@theme {
--color-brand-primary: oklch(0.65 0.24 354.31);
--font-sans: "Inter", sans-serif;
--radius-button: 0.5rem;
}
Decision Guide
- Pure utilities: 1-2 variants, simple component, no shared API needed.
- CVA: 3+ variants, type-safe props, button-like component.
- tailwind-variants: slots, responsive variants, component composition.
- Custom
@utility: rare project-specific utility. @apply: avoid unless project convention requires it.
Component Rules
- Keep base layout classes obvious.
- Put state in
data-*attributes when it affects styling. - Use
disabled,aria-disabled, andaria-busycorrectly. - Accept
classNameonly when extension is intended. - Merge classes with existing project helper, usually
cn. - Do not hide important design choices behind unclear helpers.
Migration Notes
shadow-smbecameshadow-xs.rounded-smbecamerounded-xs.bg-opacity-50becomesbg-black/50.bg-gradient-to-rbecomesbg-linear-to-r.bordernow usescurrentColor.ringnow usescurrentColor; use explicit ring width and color.
Flow
- Check existing component style patterns.
- Count variants and slots.
- Pick utilities, CVA, or tailwind-variants.
- Add tokens through
@themewhen needed. - Model state with attributes.
- Verify responsive behavior and accessibility.
Output
## Tailwind v4 Decision
- Approach: [utilities/CVA/tailwind-variants]
- Reason: [variant count, slots, or project pattern]
- Tokens: [added or none]
- Accessibility: [states and labels checked]
- Migration notes: [v3 changes or none]