A Prettier plugin that automatically sorts Tailwind CSS classes based on the recommended class order.
prettier-plugin-tailwindcss is a Prettier plugin that automatically sorts Tailwind CSS classes in HTML, JSX, and other supported syntax based on Tailwind's recommended class order. It solves the problem of inconsistent class ordering in projects using Tailwind CSS, ensuring readability and maintainability by automating sorting during code formatting.
Frontend developers and teams using Tailwind CSS with Prettier for code formatting, particularly those working on large projects where consistent class ordering improves collaboration and reduces style conflicts.
Developers choose this plugin because it integrates seamlessly with Prettier, enforces Tailwind's official class order without manual effort, and offers extensive customization for attributes, functions, and template literals, all while maintaining compatibility with other Prettier plugins.
A Prettier plugin for Tailwind CSS that automatically sorts classes based on our recommended class order.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Sorts classes in HTML attributes, JSX equivalents, and @apply directives based on Tailwind's official order, eliminating manual sorting and ensuring consistency across projects.
Supports custom attributes via tailwindAttributes with regex patterns and function calls via tailwindFunctions, allowing sorting in dynamic scenarios like clsx or custom template literals.
Exposes createSorter for standalone use, enabling class sorting outside Prettier with methods for attributes and lists, useful for build tools or custom scripts.
Includes options to preserve whitespace and duplicates for templating languages, and workarounds for compatibility with other popular Prettier plugins like prettier-plugin-svelte.
As of v0.5.x, the plugin requires Prettier v3 and is ESM-only, forcing projects using CommonJS to migrate or face compatibility issues, as noted in the upgrade guide.
Must be loaded last in Prettier's plugin list due to API limitations, complicating setups with multiple plugins and requiring explicit ordering, which can lead to integration headaches.
For Tailwind CSS v4, it requires specifying the stylesheet path with tailwindStylesheet, adding an extra configuration step that can be error-prone if paths are misconfigured.