Skip to content

no-descending-specificity

Reports a rule whose selector ends in the same compound selector (not counting its pseudo-classes) as an earlier rule in the same at-rule, and has a lower specificity. Nested rules are not compared.

For the same element the rule with higher specificity wins, whatever its place. A later rule with lower specificity (a:hover before a) never applies to what the earlier one covers, which is almost never what the author meant.

To fix, move the rule with the lower specificity up, or raise its specificity.

Reported
a:hover { color: red }
a { color: blue }
.b a { color: red }
a { color: green }
@media print { a { color: red } }
td:not([align]) { color: red }
table td { color: blue }
a[d] b { color: red }
c b { color: blue }
p:not(.c) b { color: red }
b { color: blue }
css:
lint:
rules:
no-descending-specificity: warn # off (default), warn, error
less:
lint:
rules:
no-descending-specificity: warn # off (default), warn, error
scss:
lint:
rules:
no-descending-specificity: warn # off (default), warn, error

Enabled by the presets: css/stylelint-recommended.

Suppress one line with sudsy-disable-next-line no-descending-specificity in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
stylelint no-descending-specificity full