Merge default component classes with user-provided overrides without class conflicts in React or Vue components.
Build a reusable button that accepts a className prop and correctly resolves padding or color conflicts.
Clean up dynamically generated Tailwind class strings before rendering them to the DOM.
tailwind-merge is a TypeScript utility that combines Tailwind CSS class strings and removes conflicting entries. It is installed as an npm package and used directly in JavaScript or TypeScript code. Tailwind CSS is a popular way of styling web pages by attaching short utility class names directly to HTML elements. A common problem occurs when building reusable components: if a parent component passes class names and the component also has its own defaults, both sets of classes end up in the rendered HTML. When two classes control the same CSS property (for example, "px-2" and "p-3" both affect padding), the browser applies whichever appears later in the stylesheet, which may not be what you intended. tailwind-merge handles this by analyzing the full list of class names, identifying which ones conflict, and returning a cleaned-up string where later or more specific classes win. In the example from the README, combining "px-2 py-1 bg-red hover:bg-dark-red" with "p-3 bg-[#B91C1C]" produces "hover:bg-dark-red p-3 bg-[#B91C1C]": the padding shorthand "p-3" replaces "px-2 py-1", and the custom background color replaces "bg-red". The library supports Tailwind v4.0 through v4.3. Users still on Tailwind v3 should use tailwind-merge v2.6.0 instead. The package is fully typed in TypeScript, so type checkers and code editors can surface errors when the merge function is called incorrectly. Separate documentation pages in the repository cover configuration, a plugin system for extending it with custom Tailwind settings, known limitations, and an API reference. The package size is tracked on Bundlephobia for anyone who wants to know its impact on a JavaScript bundle.
← dcastil on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.