cn utility

A tiny helper, cn(...classes) = twMerge(clsx(classes)), that joins class names conditionally and then removes conflicting Tailwind classes.

In more detail

Components wrap their own classes and the caller's className in cn, so a caller's px-8 reliably replaces the component's px-3. Without it both classes would be present and the winner would depend on stylesheet order.

Example

cn(button({ size: "sm" }), "px-8") keeps px-8 and drops the variant's px-3.

Related terms

Taught in

References