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
- Paste your HTML or JSX — Drop in a code block containing Tailwind utility classes. The tool identifies class attributes and className props automatically.
- 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.
- Copy the clean code — Copy the sorted markup back into your project. The output preserves all non-class attributes, structure, and formatting.
- 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.
| Input | Prettier (Tailwind v4) | Tailwind v3 differs? |
|---|---|---|
flex items-center mb-2 p-4 text-white bg-blue-500 | mb-2 flex items-center bg-blue-500 p-4 text-white | same in v3 |
dark:text-white text-gray-900 text-lg tracking-wide leading-tight uppercase | text-lg leading-tight tracking-wide text-gray-900 uppercase dark:text-white | v3: text-lg uppercase leading-tight tracking-wide text-gray-900 dark:text-white |
absolute top-0 left-1/2 -translate-x-1/2 z-10 | absolute top-0 left-1/2 z-10 -translate-x-1/2 | v3: 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-50 | text-sm focus:ring-2 focus:outline-none disabled:opacity-50 sm:text-base | v3: 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-8 | card my-card flex p-4 hover:underline lg:p-8 | same 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.
- Pick the version your project uses. v3 and v4 order some utilities differently: v4 puts
top-0beforeleft-1/2anduppercaseafter the colour, so four of the eight lists above come out differently. - Custom configuration is not read. The modes use Tailwind's default theme. Classes from your own theme, plugins or a prefix are treated as unknown and kept first, so the plugin in your project may place them differently.
- Grouped by category is a reading aid. It keeps variants next to their utility and groups by topic; Prettier will reorder it, so do not mix it with the plugin on one codebase.
- Order never changes the styling. Tailwind sets the CSS order in the stylesheet, so any sort is visually safe.
Sources
Checked on .
Frequently Asked Questions
📖 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