Skip to content

noDescendingSpecificity (CSS)

Language CSS
biome.json
{
"linter": {
"rules": {
"style": {
"noDescendingSpecificity": "error"
}
}
}
}

Disallow lower-specificity selectors after higher-specificity selectors.

Specificity is the priority score CSS calculates from a selector. When two selectors have the same specificity, the later declaration wins. A selector with higher specificity wins regardless of source order.

A lower-specificity selector placed later can therefore look like an override even though it cannot replace the earlier style. Ordering selectors from lower to higher specificity makes the cascade easier to read.

The rule reports likely conflicts between selectors that end with the same target under the same surrounding rules, such as @media or @layer. It cannot determine every case where two selectors match the same element.

b a { color: red; }
a { color: red; }
code-block.css:2:1 lint/style/noDescendingSpecificity ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

⚠ Descending specificity selector found. This selector specificity is (0, 0, 1)

1 │ b a { color: red; }
> 2 │ a { color: red; }
│ ^
3 │

ℹ This selector specificity is (0, 0, 2)

> 1 │ b a { color: red; }
│ ^^^
2 │ a { color: red; }
3 │

ℹ Descending specificity selector may not be applied. Consider rearranging the order of the selectors. See MDN web docs for more details.

a {
& > b { color: red; }
}
b { color: red; }
code-block.css:4:1 lint/style/noDescendingSpecificity ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

⚠ Descending specificity selector found. This selector specificity is (0, 0, 1)

2 │ & > b { color: red; }
3 │ }
> 4 │ b { color: red; }
│ ^
5 │

ℹ This selector specificity is (0, 0, 2)

1 │ a {
> 2 │ & > b { color: red; }
│ ^^^^^
3 │ }
4 │ b { color: red; }

ℹ Descending specificity selector may not be applied. Consider rearranging the order of the selectors. See MDN web docs for more details.

:root input {
color: red;
}
html input {
color: red;
}
code-block.css:4:1 lint/style/noDescendingSpecificity ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

⚠ Descending specificity selector found. This selector specificity is (0, 0, 2)

2 │ color: red;
3 │ }
> 4 │ html input {
│ ^^^^^^^^^^
5 │ color: red;
6 │ }

ℹ This selector specificity is (0, 1, 1)

> 1 │ :root input {
│ ^^^^^^^^^^^
2 │ color: red;
3 │ }

ℹ Descending specificity selector may not be applied. Consider rearranging the order of the selectors. See MDN web docs for more details.

.a th {
color: red;
}
.a .b .c th {
color: green;
}
.a .b th {
color: blue;
}
code-block.css:9:1 lint/style/noDescendingSpecificity ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

⚠ Descending specificity selector found. This selector specificity is (0, 2, 1)

7 │ }
8 │
> 9 │ .a .b th {
│ ^^^^^^^^
10 │ color: blue;
11 │ }

ℹ This selector specificity is (0, 3, 1)

3 │ }
4 │
> 5 │ .a .b .c th {
│ ^^^^^^^^^^^
6 │ color: green;
7 │ }

ℹ Descending specificity selector may not be applied. Consider rearranging the order of the selectors. See MDN web docs for more details.

a { color: red; }
b a { color: red; }
b { color: red; }
a {
& > b { color: red; }
}
a:hover { color: red; }
a { color: red; }
a b {
color: red;
}
/* The rule cannot determine that these selectors target the same elements. */
:where(a) :is(b) {
color: blue;
}
.a th {
color: red;
}
@media print {
.a .b .c th {
color: green;
}
}
@layer one {
b a { color: green; }
}
@layer two {
a { color: blue; }
}