noTailwindConflictingClasses (HTML)
Summary
Section titled “Summary”- Rule available since:
v2.6.9 - Diagnostic Category:
lint/nursery/noTailwindConflictingClasses - This rule doesn’t have a fix.
- The default severity of this rule is warning.
- This rule belongs to the following domains:
- Sources:
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "noTailwindConflictingClasses": "error" } } }}Description
Section titled “Description”Disallow Tailwind CSS classes that set the same CSS properties on an element.
When two classes in a class list set the same CSS properties, only one of them takes effect.
The other class does nothing, and it hides which style you meant to apply.
In a class attribute, Tailwind CSS decides which class wins from the order of the styles
it generates, so changing the order of the classes doesn’t change the result.
Two classes only conflict when they have the same variants.
For example, flex and md:grid don’t conflict, because md:grid only applies on wider screens.
A class that sets some of the properties of another class doesn’t conflict with it either,
so you can write p-2 px-4 to change the horizontal padding.
To make the rule aware of your own theme values and variants, point the
tailwind.stylesheet
option at the CSS file that holds your Tailwind CSS configuration. Without it, the rule
only knows the default configuration, and skips classes that use your own theme values
or variants.
Biome scans your project when this rule is enabled, so that it can read the stylesheet
and the files it imports. The scan happens even if tailwind.stylesheet isn’t set,
although the rule then only uses the default configuration.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”<div class="flex grid"></div>code-block.html:1:18 lint/nursery/noTailwindConflictingClasses ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ The Tailwind CSS class grid sets the same CSS properties as flex.
> 1 │ <div class="flex grid"></div>
│ ^^^^
2 │
ℹ The other class is here.
> 1 │ <div class="flex grid"></div>
│ ^^^^
2 │
ℹ Only one of these classes takes effect, so the other one does nothing.
ℹ Remove the class that you don't need.
ℹ 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.
<div class="p-2 hover:text-red-500 hover:text-blue-500"></div>code-block.html:1:36 lint/nursery/noTailwindConflictingClasses ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ The Tailwind CSS class hover:text-blue-500 sets the same CSS properties as hover:text-red-500.
> 1 │ <div class="p-2 hover:text-red-500 hover:text-blue-500"></div>
│ ^^^^^^^^^^^^^^^^^^^
2 │
ℹ The other class is here.
> 1 │ <div class="p-2 hover:text-red-500 hover:text-blue-500"></div>
│ ^^^^^^^^^^^^^^^^^^
2 │
ℹ Only one of these classes takes effect, so the other one does nothing.
ℹ Remove the class that you don't need.
ℹ 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.
<div class="flex w-full"></div><div class="flex md:grid"></div><div class="p-2 px-4"></div><div class="text-lg text-red-500"></div>Recognized class strings
Section titled “Recognized class strings”This rule checks the attributes and functions recognized by the top-level
tailwind configuration.
Known limitations
Section titled “Known limitations”This rule compares the classes of one string at a time. It doesn’t report classes that conflict across strings:
<div class={clsx("flex", isGrid && "grid")}></div>It only checks a class that your stylesheet declares with @utility when the
@utility rule holds nothing but declarations, and the declarations that apply to
the class each set a different property. It skips a class whose rule nests other
rules or uses @apply, and a class that more than one utility defines, such as a
name that two @utility rules declare.
It doesn’t compare classes whose variants are written in a different order,
such as sm:hover:flex and hover:sm:grid.
Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.