Prettier formats the file but leaves the Tailwind class order untouched
Your error
npx prettier --write runs without errors, but class lists keep their old order2 more lines it can showFix it fast
Most common cause, 1 of 4The plugin is installed but not listed in the Prettier config
Add the plugin to the config that Prettier reported.
// .prettierrc
{
"plugins": ["prettier-plugin-tailwindcss"]
}
// or prettier.config.js
/** @type {import('prettier').Config & import('prettier-plugin-tailwindcss').PluginOptions} */
export default {
plugins: ['prettier-plugin-tailwindcss'],
};Short answer
prettier-plugin-tailwindcss sorts nothing when Prettier never loads it: Prettier 3 removed plugin auto-loading, so list it under plugins in .prettierrc, after every other plugin. With Tailwind CSS v4, set tailwindStylesheet to your CSS entry file, and add tailwindFunctions for clsx or cva calls. Applies to Prettier 3.10 and prettier-plugin-tailwindcss 0.8.
Which cause do you have?
Leave the editor out of it and format one file from the terminal. Print the config file Prettier picks for that file, then check whether the class lists changed. No change from the terminal means the cause is in that config, which every cause below starts from.
npx prettier --find-config-path app/page.tsx
npx prettier --write app/page.tsx && git diff --stat app/page.tsxThen find the line you see in this list and open its fix:
- 1The plugin is installed but not listed in the Prettier config
The config file found above has no plugins entry, or one that does not name prettier-plugin-tailwindcss - 2Another Prettier plugin is listed after it
The plugins array names a plugin such as prettier-plugin-organize-imports or @trivago/prettier-plugin-sort-imports after prettier-plugin-tailwindcss - 3Tailwind v4 is used and tailwindStylesheet is not set
Built-in utilities get sorted, but classes from your own @theme or @utility land at the front of the list - 4The classes live in function calls or non-standard attributes
className strings are sorted, while strings passed to clsx(), cva() or a cn() helper keep their order
What does the error look like?
npx prettier --write runs without errors, but class lists keep their old orderClasses inside clsx() or cva() are never reorderedCustom theme classes are moved to the start of the class list
Cause 1 of 4
The plugin is installed but not listed in the Prettier config
You seeThe config file found above has no plugins entry, or one that does not name prettier-plugin-tailwindcss
Check
prettier-plugin-tailwindcss does nothing if Prettier never loads it, and Prettier 3 no longer searches for plugins on its own: the 3.0 release removed plugin search and asks for the plugins option or the --plugin flag. Having the package in devDependencies is not enough.
cat "$(npx prettier --find-config-path app/page.tsx)"Fix
Add the plugin to the config that Prettier reported. In a JavaScript config, the type import gives editor hints for the plugin's options.
// .prettierrc
{
"plugins": ["prettier-plugin-tailwindcss"]
}
// or prettier.config.js
/** @type {import('prettier').Config & import('prettier-plugin-tailwindcss').PluginOptions} */
export default {
plugins: ['prettier-plugin-tailwindcss'],
};Verify
Run the same write command; git diff now shows reordered class strings in that file.
npx prettier --write app/page.tsx && git diff app/page.tsxConfirmed by github.com
Cause 2 of 4
Another Prettier plugin is listed after it
You seeThe plugins array names a plugin such as prettier-plugin-organize-imports or @trivago/prettier-plugin-sort-imports after prettier-plugin-tailwindcss
Check
Class sorting can stop when a second Prettier plugin comes later in the list. The Tailwind plugin relies on Prettier APIs that only one plugin can use at a time, and its README lists explicit workarounds for a set of known plugins, all of which depend on the Tailwind plugin being loaded last.
grep -n -A6 "plugins" "$(npx prettier --find-config-path app/page.tsx)"Fix
Move prettier-plugin-tailwindcss to the end of the array and keep the others in their current order.
// .prettierrc
{
"plugins": [
"@trivago/prettier-plugin-sort-imports",
"prettier-plugin-tailwindcss"
]
}Verify
Both effects show up in one run: imports are sorted and class lists are reordered.
npx prettier --write app/page.tsx && git diff app/page.tsxConfirmed by github.com
Cause 3 of 4
Tailwind v4 is used and tailwindStylesheet is not set
You seeBuilt-in utilities get sorted, but classes from your own @theme or @utility land at the front of the list
Check
With Tailwind CSS v4 the sort looks wrong for your own classes when the plugin does not know your CSS entry point: the README says v4 projects must give it through the tailwindStylesheet option. Without your theme the plugin treats those classes as non-Tailwind classes, and Tailwind documents that such classes are always sorted to the front.
grep -rln "@import \"tailwindcss\"" app src --include="*.css" 2>/dev/nullFix
Point tailwindStylesheet at the file that imports Tailwind. The path is resolved from the folder of the Prettier config, not from the file being formatted. Tailwind v3 projects use tailwindConfig instead, needed only when tailwind.config.js sits somewhere other than next to the Prettier config.
// .prettierrc
{
"plugins": ["prettier-plugin-tailwindcss"],
"tailwindStylesheet": "./app/globals.css"
}Verify
Format again; a class such as bg-brand from your theme no longer jumps to the front of the list.
npx prettier --write app/page.tsx && git diff app/page.tsxConfirmed by github.com
Cause 4 of 4
The classes live in function calls or non-standard attributes
You seeclassName strings are sorted, while strings passed to clsx(), cva() or a cn() helper keep their order
Check
The plugin sorts class, className and the framework equivalents, plus @apply, and nothing else by default. Class strings handed to a helper such as clsx or cva, or written in an attribute with another name, stay unsorted until the config names that function or attribute.
grep -rnE "(clsx|cva|cn)\(" app components src 2>/dev/null | headFix
List the helper functions in tailwindFunctions and any custom attributes in tailwindAttributes.
// .prettierrc
{
"plugins": ["prettier-plugin-tailwindcss"],
"tailwindStylesheet": "./app/globals.css",
"tailwindFunctions": ["clsx", "cva", "cn"],
"tailwindAttributes": ["containerClassName"]
}Verify
The strings inside those calls are reordered on the next write.
npx prettier --write "components/**/*.tsx"Confirmed by github.com
How do I stop it coming back?
- Add npx prettier --check . to CI, so an unloaded plugin shows up as unformatted files instead of passing silently.
- Pin prettier and prettier-plugin-tailwindcss together in devDependencies; the plugin needs Prettier 3.
- When a new Prettier plugin is added, keep prettier-plugin-tailwindcss as the last entry in the plugins array.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine on the same stack: TaxiDex.