Skip to main content

Search rules

Search all UI Guides rules by name, category, or source

formsTailwind

cn() Utility Pattern

SHOULD

SHOULD: Create cn() utility combining clsx + tailwind-merge for conditional class merging

Create a cn() utility combining clsx and tailwind-merge

Bad

Good

Why it matters

The cn() utility is a standard pattern that combines clsx (for conditional class logic) with tailwind-merge (for conflict resolution). This provides the best of both worlds for component styling.

Built by Gleb Stroganov, design engineer at Evil Martians.

The rules come from other people's skills and guidelines — Vercel, Rauno Freiberg, @Ibelick, impeccable, Emil Kowalski, Tailwind, RAMS — each one credited on the Sources page. The work here is extraction and wiring: every rule is pulled into one corpus, given a good and a bad example you can operate, a MUST/SHOULD/NEVER rule an agent can paste, and a link back to where it came from.