Excessive CSS specificity and overrides
- CSS
Problem Summary
Excessive CSS specificity and overrides cause the browser to do more work matching selectors. Deep nesting, overly specific selectors, and !important usage make CSS hard to maintain and slower to parse.
Performance Impact
- Slow selector matching: Browser works harder to apply styles
- Maintenance nightmare: Hard to override without more specificity
- Larger stylesheets: More rules needed to override
- Repaint issues: Style recalculations take longer
How to Detect
- Chrome DevTools: Check computed styles
- CSS analysis tools: Specificity calculators
- Chrome Coverage: Shows unused CSS
Solutions
1. Use Low-Specificity Selectors
/* Good */.site-header { background: #fff; }/* Avoid */body #header .nav ul li a.nav-link { background: #fff; }2. Avoid !important
Use cascade instead.
3>Use BEM or Similar Methodology
.block__element--modifier4. Flatten Nesting
Avoid deep nesting in Sass/CSS.