Skip to content

tailwind

npm version License: MIT Node.js

> Prettier configuration with Tailwind CSS class sorting. Extends @jmlweb/prettier-config-base.

> πŸ”§ Maintenance mode: dependency and security updates only, no new rules. New projects should use @jmlweb/oxfmt-config-base with its sortTailwindcss option. To migrate, see the migration guide.

  • 🎨 Class sorting: orders Tailwind classes in the recommended order
  • πŸ”§ Base included: inherits every setting from @jmlweb/prettier-config-base
  • πŸ“¦ Plugin bundled: ships prettier-plugin-tailwindcss as a dependency
  • πŸš€ Zero config: works out of the box
Terminal window
npm install --save-dev @jmlweb/prettier-config-tailwind prettier

> πŸ’‘ Upgrading? See the Migration Guide.

Create .prettierrc.mjs:

export { default } from '@jmlweb/prettier-config-tailwind';

Alternatives:

{
"prettier": "@jmlweb/prettier-config-tailwind"
}

> ⚠️ In projects with "type": "module", the package.json field can make Prettier warn Ignored unknown option { default: ... } and skip the config (no class sorting). Use .prettierrc.mjs instead.

For CommonJS (.prettierrc.cjs):

module.exports = require('@jmlweb/prettier-config-tailwind');

Before:

<button className="px-4 py-2 bg-blue-500 text-white rounded-lg hover:bg-blue-600">
Click me
</button>

After:

<button className="rounded-lg bg-blue-500 px-4 py-2 text-white hover:bg-blue-600">
Click me
</button>

The config is the base config plus:

Option Value Description
plugins ['prettier-plugin-tailwindcss'] Sorts Tailwind CSS classes
  • βœ… Projects using Tailwind CSS
  • βœ… Automatic, consistent class order

Not for you if:

.prettierrc.mjs
import tailwindConfig from '@jmlweb/prettier-config-tailwind';
export default {
...tailwindConfig,
printWidth: 100,
};
{
"scripts": {
"format": "prettier --write .",
"format:check": "prettier --check ."
}
}
Terminal window
npm run format # format all files
npm run format:check # check without writing
  • Node.js >= 22.12.0
  • Prettier >= 3.0.0
  • prettier (^3.0.0)

prettier-plugin-tailwindcss is a regular dependency, so it needs no separate install.

Breaking: Node.js >= 22.12.0 is required (18 and 20 are end-of-life).

  1. Upgrade Node.js to 22.12.0 or later.
  2. Update: npm install --save-dev @jmlweb/prettier-config-tailwind@latest

See the Changelog for details.

MIT