Skip to content

Menu

Tailwind Class Sorter

Sort Tailwind CSS classes by official order

Runs entirely in your browserFrontendFree, no sign-up
Loading tool

01What is Tailwind Class Sorter?

Long Tailwind class strings get hard to read once a few people have added to them. The usual fix is prettier-plugin-tailwindcss, the official Prettier plugin. It sorts classes by asking Tailwind how each one compiles, not by a hand-made category list. This page reproduces that order offline, for cases where Prettier isn't set up or you just want one string fixed. How does it know the order without running Tailwind? The sort data was generated from tailwindcss 4.3.5 with the default theme. For every utility it stored which CSS properties the class sets, plus Tailwind's internal property order and variant order. That table ships inside the page, so sorting happens in your browser and your markup never leaves it. The comparison follows Tailwind's own rules. Classes with no variant come first. Variant classes follow, grouped by variant in Tailwind's order, so hover comes before focus, sm before md, and arbitrary variants like [&>svg] go last. Within a group, classes sort by the properties they set, then by how many declarations they produce, then by a number-aware name compare. That last step is why p-2 lands before p-10. A quick run shows it. Paste p-4 flex text-white bg-blue-500 and you get flex bg-blue-500 p-4 text-white. Display comes first, then background, then padding, then text colour, because that's the CSS property order Tailwind uses. The parser understands arbitrary values like w-[37px], CSS variable shorthands like text-(--brand), and arbitrary properties like [mask-type:luminance]. It also handles opacity modifiers such as bg-red-500/50 and the ! important flag. The tool's source notes it was checked against prettier-plugin-tailwindcss 0.8.1 on more than 1,000 random class lists. Classes it can't match are kept at the front in their original order, which is what the plugin does too. The page lists them separately. That list is handy, because a typo like itmes-center shows up there instead of silently landing somewhere odd. The main limit is the theme. Utilities that only exist in your own config, such as bg-brand, are treated as unknown, while the real plugin reading your config would place them by property. Old v3 utilities that v4 dropped, like bg-opacity-50, are unknown too. For sorting a whole repository on save, install the plugin itself.

Front-end developers on Tailwind CSS v4 who want the official Prettier plugin's class order for a single string without setting up Prettier. The tool runs entirely in your browser, so your data never leaves your device.

02How to use Tailwind Class Sorter

  1. Paste a space-separated class list into Input Classes, or load one of the examples.
  2. Read the sorted output along with the class count and how many classes moved.
  3. Check the not-recognised list for typos, custom theme names or v3-only utilities.
  4. Click Copy Sorted and paste the result back into your markup.

03Worked examples

Input: p-4 flex text-white bg-blue-500
Result: flex bg-blue-500 p-4 text-white
Ordered by the CSS property each class sets.
Input: hover:bg-red-500 bg-red-400 md:p-8 p-2
Result: bg-red-400 p-2 hover:bg-red-500 md:p-8
Classes without a variant come first, then hover:, then md:.
Input: mt-4 mb-2 m-1
Result: m-1 mt-4 mb-2
The margin shorthand comes before the single-side margins.
Input: text-sm my-custom-class font-bold
Result: my-custom-class text-sm font-bold
my-custom-class isn't a Tailwind utility, so it goes first and is listed as not recognised.
Input: lg:p-8 md:p-4 sm:p-2 p-1
Result: p-1 sm:p-2 md:p-4 lg:p-8
Breakpoint variants follow Tailwind's variant order.
Input: p-10 p-2 hover:bg-white bg-red-500/50 !mt-2 bg-opacity-50
Result: bg-opacity-50 !mt-2 bg-red-500/50 p-2 p-10 hover:bg-white
bg-opacity-50 was removed in v4, so it's unknown and moved first. p-2 sorts before p-10 thanks to the number-aware compare.

04Common use cases

  • Tidying a long className on a React or Vue component before opening a pull request
  • Getting plugin-matching order in a CodePen, CMS snippet or project where Prettier isn't installed
  • Making a crowded utility string easier to scan while debugging why a layout breaks at md
  • Cleaning up classes copied from a UI kit or docs example so they match the rest of the codebase
  • Catching typos, since a misspelled utility appears in the not-recognised list
  • Spotting leftover Tailwind v3 classes like bg-opacity-50 during a v4 migration

05Tips

  • Utilities from your own theme, like bg-brand, are treated as unknown and moved to the front. The real plugin with your config would place them by property.
  • Classes with stacked variants, like dark:hover:bg-black, sort after classes that use only one of those variants.
  • Paste only the class string, not the whole className attribute. Quotes and braces would be treated as class names.
  • Responsive prefixes end up in breakpoint order, so p-1 sm:p-2 md:p-4 lg:p-8 reads as a ladder.
  • For a whole codebase, install prettier-plugin-tailwindcss so sorting runs on save with your exact config.

06Related concepts

Tailwind CSS, Utility-first CSS, Responsive variants, Prettier, Class ordering.

Frequently Asked Questions

What is Tailwind Class Sorter?

Tailwind Class Sorter is a free, browser-based developer tool on AIDToolStack. Sort Tailwind CSS classes by official order It requires no installation or sign-up and works entirely in your browser.

Is Tailwind Class Sorter free to use?

Yes. No sign-up, no fees and no usage cap.

Does Tailwind Class Sorter store my data?

No. It runs in your browser; nothing is uploaded.

Reviews and commentsShow

Reviews

Sign in to leave a review.

Loading reviews…

Comments

Sign in to leave a comment.

Loading comments…

What changed in AI dev tools, once a month

Renames, shutdowns, pricing changes and new MCP setups, each with a source.

Subscribe