A Prettier plugin that sorts HTML class attributes alphabetically or with a custom order file. Version 3.0.1 supports HTML, CSS @apply, JSX/TSX, and twin.macro. It automatically detects the plugin when installed alongside Prettier 2.x. Unlike similar tools (e.g., prettier-plugin-tailwindcss), this plugin offers flexible ordering via an external file and custom prefixes for responsive variants. Maintenance is community-driven.
npm install prettier-plugin-sort-class-namesVerified import paths — ran on the pinned version, not inferred.
Installs the plugin and shows it sorts classes alphabetically in an HTML file.
Use only one class-sorting plugin to avoid conflicting sorts.
Use a prettier.config.js file with plugins: [require('prettier-plugin-sort-class-names')].Use an absolute path or ensure process.cwd() is set correctly.
Set sortClassNamesUnknownClassesSeparator: '' in config to disable.
Consider using a fork or updating if plugin supports Prettier 3.
Install the plugin or add require('prettier-plugin-sort-class-names') in prettier.config.js plugins array.Downgrade to Prettier 2.x or use a compatible plugin version.
Set option as string: 'sm:,md:,lg:'.