Tailwind v4
Rule
Configuration
- MUST: Use config-free setup only; do not add
tailwind.config.*files. - MUST: Use PostCSS with
@tailwindcss/postcssplugin. - MUST: Configure source paths with
@sourcedirectives in CSS. - MUST: App imports Tailwind CSS once (e.g., in
globals.css).
Source Paths
- MUST:
@sourceglobs cover every directory where class names appear. - NEVER: Safelist classes — fix
@sourceor token mapping instead.
@import "tailwindcss";
@source "../**/*.{ts,tsx}";
For monorepos, add @source entries for shared UI packages and app sources.
Theme Tokens
- MUST: Map CSS variables to Tailwind tokens via
@themeso utilities likebg-primarywork. - MUST: Token mappings cover the utilities your components use.
@theme {
--color-primary: hsl(var(--primary));
--color-primary-foreground: hsl(var(--primary-foreground));
}
Gray Palette
- MUST: Pick one neutral palette (e.g.,
gray,zinc,slate) and use it consistently. - NEVER: Mix multiple neutral palettes in the same project.
Utilities
- MUST: Use
cnutility (clsx+tailwind-merge) for conditional class logic. - MUST: Use
cva(class-variance-authority) for component variants. - SHOULD: Use
size-*for square elements instead ofw-* h-*. - NEVER: Rely on
importanthacks.