Class order
annealer can reorder the classes inside static class attributes. The order comes from a class order profile, a YAML file separate from the attribute profile, so it can be swapped for another library's order.
It is off by default. Turn it on with a class order name or file:
An attribute profile can also name one with classOrder. --class-order and the classOrder option override it.
Built-in: tailwind
The built-in tailwind class order follows the order that eslint-plugin-tailwindcss (classnames-order) and prettier-plugin-tailwindcss apply. Both take it from the Tailwind CSS compiler.
annealer doesn't run Tailwind. The order is data, generated from Tailwind CSS 4.3 with its default theme by scripts/generate-tailwind-order.mjs. The same script writes a test corpus of 3,000 class lists sorted by Tailwind itself, and annealer's output matches all of them.
Differences from running Tailwind:
- Your own theme and utilities aren't known. A custom color (
bg-brand-500) is ordered like a theme color, because a value that matches no other rule falls back to the color rule. A custom utility (@utility) is an unknown class. - Duplicates are kept.
eslint-plugin-tailwindcssremoves them by default (removeDuplicates). Removing classes is a lint concern, so the built-in profile keeps them. A class order withremoveDuplicates: trueremoves them. - Only static
classattributes.:classbindings andclsx()-style calls are expressions, and annealer never reads them.
How classes are ordered
- Classes no rule matches (
card,js-toggle) go first, in their source order (unknown: endputs them last). - Classes without variants come first. Classes with variants follow, by the ranks of their variants (
variants.order). The highest rank decides, like comparing bit masks. - Then by the CSS properties a class sets: the first property that differs, by its position in
propertyOrder. - Then more properties first (
count). - Then by name, with runs of digits compared as numbers (
p-2beforep-10).
This is the comparison Tailwind uses. Nothing in it is specific to Tailwind: any utility library can describe its classes by the properties they set.
What changes in the markup
- Whitespace stays in place: classes move between the existing separators, so multi-line class lists keep their line breaks.
- Values with template syntax (
{{ }},{% %},<?php ?>,${}) and unquoted values are left as written. - Disable directives apply as for attributes.
Writing a class order
matchpatterns:*matches any run of characters;{name}matches one entry of a value set invalues.{number}(a decimal number) is built in.- The most specific pattern wins: an exact name, then the most literal characters, then the most value sets.
- A modifier after
/(bg-red-500/50) is ignored when the class without it matches better.
See the class order reference for every key. builtinClassOrder('tailwind') in the JavaScript API returns the built-in YAML as a starting point.