A VS Code extension that automatically sorts Tailwind CSS classes in the recommended order using prettier-plugin-tailwindcss. No Prettier setup required — just install and run.
Sort Tailwind CSS Classes from the Command Palette (Ctrl+Shift+P / Cmd+Shift+P)@import "tailwindcss") and v3 (tailwind.config.js)clsx(), cn(), cva(), tw(), and any custom functions you configure.prettierrc to preserve code style; only class order changesCtrl+Shift+P / Cmd+Shift+P).Enable automatic sorting on save in your VS Code settings:
{
"tailwindClassSorter.formatOnSave": true
}
| Setting | Type | Default | Description |
|---|---|---|---|
tailwindClassSorter.formatOnSave |
boolean |
false |
Automatically sort Tailwind CSS classes on file save |
tailwindClassSorter.tailwindStylesheet |
string |
"" |
(Tailwind v4) Path to your Tailwind CSS entry point (e.g. ./src/app.css). Leave empty for auto-detection |
tailwindClassSorter.tailwindConfigPath |
string |
"" |
(Tailwind v3) Path to tailwind.config.js (relative to workspace root). Leave empty for auto-detection |
tailwindClassSorter.tailwindFunctions |
string[] |
["clsx", "cn", "cva", "tw"] |
Function names whose arguments should have their Tailwind classes sorted |
tailwindClassSorter.tailwindAttributes |
string[] |
["class", "className"] |
HTML/JSX attributes whose values should have their Tailwind classes sorted |
Before:
<div class="p-4 flex bg-white items-center shadow-lg rounded-lg justify-between">Hello</div>
After:
<div class="flex items-center justify-between rounded-lg bg-white p-4 shadow-lg">Hello</div>
This extension uses prettier-plugin-tailwindcss under the hood to sort your classes into Tailwind's recommended order. It bundles Prettier and the plugin internally — you don't need to install or configure either in your project.
The sorting follows the same order as Tailwind's official Prettier plugin: layout utilities first (like flex, grid), then spacing, sizing, typography, backgrounds, borders, effects, and finally state modifiers (hover:, focus:, dark:, etc.).
Found a bug or have a feature request? Open an issue on GitHub.
Pull requests are welcome!
MIT — made by @mr-kasper