Skip to content

useTailwindSortedClasses (JavaScript)

biome.json
{
"linter": {
"rules": {
"nursery": {
"useTailwindSortedClasses": "error"
}
}
}
}

Enforce the sorting of Tailwind CSS classes.

Classes are sorted in the same order as the official Tailwind CSS Prettier plugin, which is the order in which Tailwind CSS writes their CSS. Classes that Tailwind CSS doesn’t know, such as your own CSS classes, come first and keep their original order.

<div class="px-2 foo p-4 bar" />;
code-block.jsx:1:12 lint/nursery/useTailwindSortedClasses  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ These CSS classes should be sorted.

> 1 │ <div class="px-2 foo p-4 bar" />;
│ ^^^^^^^^^^^^^^^^^^
2 │

ℹ A consistent class order makes class lists easier to read and keeps changes to them small.

ℹ This rule is still being actively worked on, so it may be missing features or have rough edges. Visit https://github.com/biomejs/biome/issues/1274 for more information or to report possible bugs.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

ℹ Unsafe fix: Sort the classes.

1 │ - <div·class="px-2·foo·p-4·bar"·/>;
1 │ + <div·class="foo·bar·p-4·px-2"·/>;
2 2 │

<div class="hover:focus:m-2 foo hover:px-2 p-4" />
code-block.jsx:1:12 lint/nursery/useTailwindSortedClasses  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ These CSS classes should be sorted.

> 1 │ <div class="hover:focus:m-2 foo hover:px-2 p-4" />
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │

ℹ A consistent class order makes class lists easier to read and keeps changes to them small.

ℹ This rule is still being actively worked on, so it may be missing features or have rough edges. Visit https://github.com/biomejs/biome/issues/1274 for more information or to report possible bugs.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

ℹ Unsafe fix: Sort the classes.

1 │ - <div·class="hover:focus:m-2·foo·hover:px-2·p-4"·/>
1 │ + <div·class="foo·p-4·hover:px-2·hover:focus:m-2"·/>
2 2 │

<div class="foo bar p-4 px-2" />;

This rule checks the attributes and functions recognized by the top-level tailwind configuration.

The Tailwind CSS Prettier plugin preserves all original whitespace. This rule, however, collapses all whitespace (including newlines) into single spaces.

This is a deliberate decision. We’re unsure about this behavior, and would appreciate feedback on it. If this is a problem for you, please share a detailed explanation of your use case in the GitHub issue.