tailwind-merge
A JavaScript library that removes Tailwind classes overridden by later ones in the same list, such as dropping p-4 when px-6 follows.
In more detail
It understands which utilities set the same CSS property, so it keeps only the last of a conflicting group. That makes class overrides predictable regardless of how the stylesheet orders the rules.
Related terms
- cn utility — A tiny helper, cn(...classes) = twMerge(clsx(classes)), that joins class names conditionally and then removes conflicting Tailwind classes.
- clsx — A tiny JavaScript function that builds a class string from strings, objects and conditions, skipping anything falsy.
- Tailwind CSS — A CSS framework made of small single-purpose utility classes, such as bg-blue-600 or px-4, that you combine in markup.
Taught in
- Class Variance Authority: Type-Safe Variant & Prop Orchestration — Design Systems & Component Engineering