no-descending-specificity
CSS / SCSS / LessCSS / SCSS / LessCSS / SCSS / Lesssuspiciousno fixdefault: offcss/stylelint-recommended
What it does
Section titled “What it does”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.
Why it matters
Section titled “Why it matters”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.
Example
Section titled “Example”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 }Configuration
Section titled “Configuration”css: lint: rules: no-descending-specificity: warn # off (default), warn, errorless: lint: rules: no-descending-specificity: warn # off (default), warn, errorscss: lint: rules: no-descending-specificity: warn # off (default), warn, errorEnabled 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.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| stylelint | no-descending-specificity |
full |