Tailwind Class Sorter

What Is a Tailwind Class Sorter?

A Tailwind class sorter takes messy, randomly-ordered utility classes and reorders them into a logical, consistent sequence. When a div has classes like p-4 flex text-white bg-blue-500 items-center mb-2, the sorter rearranges them to flex items-center mb-2 p-4 bg-blue-500 text-white — layout first, then spacing, background, text.

The grouping is similar to the official Tailwind CSS Prettier plugin, though not identical (see the FAQ). Consistent ordering makes large codebases easier to read, reduces merge conflicts, and helps team members quickly find specific utilities in long class strings.

How to Use This Tool

  1. Paste your HTML or JSX — Drop in a code block containing Tailwind utility classes. The tool identifies class attributes and className props automatically.
  2. Review the sorted output — The tool highlights what changed — reordered classes are visually marked so you can see the before and after for each element.
  3. Copy the clean code — Copy the sorted markup back into your project. The output preserves all non-class attributes, structure, and formatting.
  4. Use it as part of your workflow — Run your components through the sorter during code review or before committing to keep class ordering consistent across your codebase.

Worked example: the same order as the Prettier plugin

The two Prettier modes run Tailwind's own ordering code in your browser: Tailwind CSS 4.3.3 or 3.4.17 with its default configuration, loaded once (about 80 KB compressed) when you pick the mode. Classes are then compared exactly as prettier-plugin-tailwindcss 0.8.1 compares them: classes Tailwind does not know come first in their original order, Tailwind classes follow in the order Tailwind writes their CSS, and a repeated Tailwind class is kept once.

InputPrettier (Tailwind v4)Tailwind v3 differs?
flex items-center mb-2 p-4 text-white bg-blue-500mb-2 flex items-center bg-blue-500 p-4 text-whitesame in v3
dark:text-white text-gray-900 text-lg tracking-wide leading-tight uppercasetext-lg leading-tight tracking-wide text-gray-900 uppercase dark:text-whitev3: text-lg uppercase leading-tight tracking-wide text-gray-900 dark:text-white
absolute top-0 left-1/2 -translate-x-1/2 z-10absolute top-0 left-1/2 z-10 -translate-x-1/2v3: absolute left-1/2 top-0 z-10 -translate-x-1/2
sm:text-base text-sm focus:outline-none focus:ring-2 disabled:opacity-50text-sm focus:ring-2 focus:outline-none disabled:opacity-50 sm:text-basev3: text-sm focus:outline-none focus:ring-2 disabled:opacity-50 sm:text-base
card my-card p-4 flex p-4 hover:underline lg:p-8card my-card flex p-4 hover:underline lg:p-8same in v3 (unknown classes first, second p-4 removed)

On October 13, 2026 we checked both modes against the real plugin (Prettier 3.9.10, plugin 0.8.1) in a Tailwind 4.3.3 project and a Tailwind 3.4.17 project: the 8 lists from this page plus 300 generated lists mixing utilities, variants (hover:, md:, dark:, group-hover:, aria-expanded:), arbitrary values, important markers, negative values, unknown classes and duplicates. Tailwind v4 mode matched 308 of 308, Tailwind v3 mode 308 of 308. The same 8 lists gave identical output in the page in Chromium at desktop and 390px widths. Before this change the old "Recommended" order matched the plugin on 0 of 8.

Frequently Asked Questions

What is a Tailwind class sorter?+
A tool that reorders utility classes in a consistent sequence so markup is easier to scan and diffs stay small. This one uses its own category grouping, not the official Prettier plugin order; in our test none of eight class lists matched the plugin's output.
Why does class order matter?+
Consistent class ordering improves code readability and makes it easier for teams to scan and review markup. It also reduces meaningless diff noise in version control — when everyone sorts classes the same way, pull requests only show real changes.
Does this change the CSS output?+
No. Reordering classes has zero effect on how Tailwind renders styles. CSS specificity is determined by the stylesheet order, not the HTML class attribute order. Sorting is purely a readability improvement.
What ordering convention does it follow?+
By default, Tailwind's own order, the one prettier-plugin-tailwindcss applies: unknown classes first, then utilities in the order Tailwind generates their CSS, with variant classes such as hover: and md: after the base utilities. Choose Tailwind v4 or v3 to match your project. Grouped by category, alphabetical, reverse and length orders are also available.
Can I paste JSX or Vue templates?+
Yes. If the input contains markup, every static class="..." and className="..." attribute is sorted in place and the rest of your HTML, JSX, Vue or Svelte markup is returned unchanged. Dynamic bindings such as :class="{...}", className={clsx(...)} or template literals are left alone. If you paste a bare list of classes instead, you get back a sorted class="..." attribute.
Does it remove duplicate classes?+
In the Prettier modes, a Tailwind class that appears twice is kept once, as the plugin does, and unknown classes are left alone; the tool lists what it removed. The other modes keep one copy of every repeated class.
Which Tailwind sorting order does the tool use?+
The Prettier modes run Tailwind 4.3.3 or 3.4.17's own class-ordering code with the default configuration, so the result equals prettier-plugin-tailwindcss 0.8.1: in our check 308 of 308 lists matched for each version. Custom theme values, plugins and prefixes are not read and are treated as unknown classes.
Does the sorter handle arbitrary values and important modifiers?+
Yes. In the Prettier modes arbitrary values like p-[3px], arbitrary properties like [mask-type:luminance], opacity modifiers like bg-red-500/50, negative values and the ! marker are ordered by Tailwind itself, the same way the plugin orders them.

📖 Learn More

Related Article How to Convert CSS to Tailwind → Related Article Tailwind CSS Colors Guide →

Built by Derek Giordano · Part of Ultimate Design Tools

Privacy Policy · Terms of Service