tailwind-merge

2026-11-29

Utility library to merge Tailwind CSS classes without style conflicts.

Upstream URL

github.com/40ants/tailwind-merge

Author

Alexander Artemenko <svetlyak.40wt@gmail.com>

License

Unlicense
README

tailwind-merge - Utility library to merge Tailwind CSS classes without style conflicts.

TAILWIND-MERGE ASDF System Details

Installation

You can install this library from Quicklisp, but you want to receive updates quickly, then install it from Ultralisp.org:

(ql-dist:install-dist "http://dist.ultralisp.org/"
                      :prompt nil)
(ql:quickload :tailwind-merge)

Usage

The tailwind-merge:merge-tailwind-classes function allows you to merge Tailwind CSS classes while resolving conflicts between them. It keeps the last class in case of conflicts.

;; Basic class merging - conflicting classes are resolved by keeping the last one
(merge-tailwind-classes '("px-2" "px-3"))
;; => ("px-3")

(merge-tailwind-classes '("py-2" "px-3"))
;; => ("py-2" "px-3")  ; Non-conflicting classes are both kept

(merge-tailwind-classes '("bg-red-500" "bg-blue-500"))
;; => ("bg-blue-500")

;; Conflict resolution - the last class wins
(merge-tailwind-classes '("h-10" "h-min"))
;; => ("h-min")

(merge-tailwind-classes '("mix-blend-normal" "mix-blend-multiply"))
;; => ("mix-blend-multiply")

;; Non-conflicting classes are preserved
(merge-tailwind-classes '("stroke-black" "stroke-1"))
;; => ("stroke-black" "stroke-1")

(merge-tailwind-classes '("outline-black" "outline-1"))
;; => ("outline-black" "outline-1")

;; Arbitrary values support
(merge-tailwind-classes '("stroke-2" "stroke-[3]"))
;; => ("stroke-[3]")

(merge-tailwind-classes '("grayscale-0" "grayscale-[50%]"))
;; => ("grayscale-[50%]")

(merge-tailwind-classes '("grow" "grow-[2]"))
;; => ("grow-[2]")

API

TAILWIND-MERGE/MERGER

package tailwind-merge/merger

Functions

function tailwind-merge/merger:merge-tailwind-classes classes

Merges Tailwind CSS classes while resolving conflicts between them.

This function takes a list of CSS class strings and returns a new list with conflicting classes resolved. When multiple classes from the same group are present, only the last one (in order) is kept, effectively overriding the previous ones.

For example, if both 'px-2' and 'px-3' are in the input, only 'px-3' will appear in the output since both belong to the same padding-x group.

Non-conflicting classes are preserved in the output.

Args:

  • CLASSES: A list of strings representing Tailwind CSS classes.

Returns:

A list of strings with conflicting classes resolved, keeping only the last class in case of conflicts.

Examples:

(merge-tailwind-classes '("px-2" "px-3"))
;; => ("px-3")

(merge-tailwind-classes '("py-2" "px-3"))
;; => ("py-2" "px-3")

(merge-tailwind-classes '("bg-red-500" "bg-blue-500"))
;; => ("bg-blue-500")

(merge-tailwind-classes '("p-2" "hover:p-4"))
;; => ("p-2" "hover:p-4")

(merge-tailwind-classes '("hover:p-2" "hover:p-4"))
;; => ("hover:p-4")

(merge-tailwind-classes '("hover:focus:p-2" "focus:hover:p-4"))
;; => ("focus:hover:p-4")

TAILWIND-MERGE/VALIDATORS

package tailwind-merge/validators

Functions

function tailwind-merge/validators:colorp value

Matches Tailwind CSS color values like 'slate-600', 'red-500', 'black', 'white', 'transparent', etc.

function tailwind-merge/validators:empty-or-number-p value

Matches empty string or number values (for classes like 'border' or 'border-2').

function tailwind-merge/validators:fraction-value-p value

Matches fractions like 1/2, 1/3, 2/3, etc.

function tailwind-merge/validators:integer-value-p value

Matches integer values like 0, 1, 2, 100, etc.

function tailwind-merge/validators:make-validators-from-rule rule

function tailwind-merge/validators:number-value-p value

Matches any number including decimals like 0.5, 1.5, etc.

function tailwind-merge/validators:percent-value-p value

Matches percentage values like 50%, 100%, etc.

function tailwind-merge/validators:tshirt-size-p value

Matches t-shirt sizes like xs, sm, md, lg, xl, 2xl, 3xl, etc.

TAILWIND-MERGE/VARS

package tailwind-merge/vars

Variables

variable tailwind-merge/vars:*basic-color-names* ("black" "white" "transparent" "current" "inherit")

TailwindCSS basic color names which do not have a shade.

variable tailwind-merge/vars:*color-names* ("slate" "gray" "zinc" "neutral" "stone" "red" "orange" "amber" "yellow" "lime"

"green" "emerald" "teal" "cyan" "sky" "blue" "indigo" "violet" "purple" "fuchsia" "pink" "rose" "black" "white")

TailwindCSS color names.

variable tailwind-merge/vars:*color-shades* ("50" "100" "200" "300" "400" "500" "600" "700" "800" "900" "950")

TailwindCSS color names.


[generated by 40ANTS-DOC]

Dependencies (11)

  • 40ants-asdf-system
  • alexandria
  • ci
  • cl-hamcrest
  • doc
  • docs-builder
  • named-readtables
  • parse-number
  • pythonic-string-reader
  • rove
  • serapeum

Dependents (1)

  • GitHub
  • Quicklisp