CSS selector complexity
What a css-selector-complexity finding of fallow health means, why it matters and how to fix it.
What it reports
CSS selector, nesting, or important usage is structurally complex.
Styling explains how fallow finds it.
Why it matters
A selector with high specificity or !important wins over later rules, so the next style change needs a stronger selector. A long descendant chain also breaks when the markup changes.
Example
.sidebar nav ul li a.active sits four levels deep in nested SCSS, and its block uses !important on most declarations.
Fix
Flatten the nesting, put a class on the element instead of a long descendant chain, and remove !important where the order of the rules can do the work.
Facts
| Fact | Value |
|---|---|
| Issue type | css-selector-complexity |
| Rule id in SARIF output | fallow/css-selector-complexity |
| Command | fallow health |
| Default severity | warn |
Config key in rules | css-selector-complexity |
| Suppression comment | // fallow-ignore-next-line css-selector-complexity |
Fixable with fallow fix | No |
| Opt-in | No |
When to keep the code
- A reset rule, an accessibility rule, or a rule that overrides markup of another library can need a strong selector.