Compose Tailwind classes with cva, clsx, and TwMerge
ShardUI keeps component styling close to the markup without letting class strings become noise.
Use cva to turn design choices
into reusable variant recipes, clsx
to keep conditional classes readable, and TwMerge
through CssUtils.cn so caller overrides resolve predictably instead of piling up
conflicting Tailwind utilities.
clsx builds the class string from base classes, conditional values, and user
classes. CssUtils.cn then merges that result with TwMerge.
Preview card
Try adding p-2, bg-destructive, or rounded-full.
Raw clsx result
rounded-md border border-input bg-background p-4 text-sm text-foreground transition-colors border-primary bg-primary/10 text-primary p-6 rounded-xl shadow-mdAfter CssUtils.cn
border text-sm transition-colors border-primary bg-primary/10 text-primary p-6 rounded-xl shadow-mdcva owns the stable component recipe. clsx still handles one-off
conditions, and TwMerge keeps consumer overrides ergonomic.
Try bg-primary text-primary-foreground px-8 when you want to see caller classes
intentionally override the selected variants.
Intent
Success
Size
Md
Density
Cozy
cva + clsx result
inline-flex items-center justify-center rounded-md border text-sm font-medium shadow-xs transition-all outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 border-emerald-500/30 bg-emerald-500/10 text-emerald-700 hover:bg-emerald-500/20 dark:text-emerald-300 h-9 px-4 py-2 gap-2 [&_svg:not([class*='size-'])]:size-4 shadow-mdAfter CssUtils.cn
inline-flex items-center justify-center rounded-md border text-sm font-medium transition-all outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 border-emerald-500/30 bg-emerald-500/10 text-emerald-700 hover:bg-emerald-500/20 dark:text-emerald-300 h-9 px-4 py-2 gap-2 [&_svg:not([class*='size-'])]:size-4 shadow-md