You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Tailwind CSS 4 patterns and best practices. Trigger: When styling with Tailwind (className, variants, cn()), especially when dynamic styling or CSS variables are involved (no var() in className).
Tailwind class exists? → className="..."
Dynamic value? → style={{ width: `${x}%` }}
Conditional styles? → cn("base", condition && "variant")
Static only? → className="..." (no cn() needed)
Library can't use class?→ style prop with var() constants
Critical Rules
Never Use var() in className
// ❌ NEVER: var() in className<divclassName="bg-[var(--color-primary)]"/><divclassName="text-[var(--text-color)]"/>// ✅ ALWAYS: Use Tailwind semantic classes<divclassName="bg-primary"/><divclassName="text-slate-400"/>
Never Use Hex Colors
// ❌ NEVER: Hex colors in className<pclassName="text-[#ffffff]"/><divclassName="bg-[#1e293b]"/>// ✅ ALWAYS: Use Tailwind color classes<pclassName="text-white"/><divclassName="bg-slate-800"/>
// ❌ Static classes - unnecessary wrapper<divclassName={cn("flex items-center gap-2")}/>// ✅ Just use className directly<divclassName="flex items-center gap-2"/>
Style Constants for Charts/Libraries
When libraries don't accept className (like Recharts):
// ✅ Constants with var() - ONLY for library propsconstCHART_COLORS={primary: "var(--color-primary)",secondary: "var(--color-secondary)",text: "var(--color-text)",gridLine: "var(--color-border)",};// Usage with Recharts (can't use className)<XAxistick={{fill: CHART_COLORS.text}}/><CartesianGridstroke={CHART_COLORS.gridLine}/>
// ✅ OK for one-off values not in design system<divclassName="w-[327px]"/><divclassName="top-[117px]"/><divclassName="grid-cols-[1fr_2fr_1fr]"/>// ❌ Don't use for colors - use theme instead<divclassName="bg-[#1e293b]"/>// NO