Performance: Nesting depth and best practices
MEDIUM IMPACT
This affects CSS parsing speed, style calculation, and layout performance in the browser.
$button-color: blue; .button { color: $button-color; } .button-icon-path { fill: red; }
$button-color: blue; .button { color: $button-color; .icon { svg { path { fill: red; } } } }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Deeply nested selectors | No extra DOM nodes but complex matching | Multiple reflows if styles change | Higher paint cost due to complex styles | [X] Bad |
| Flat, simple selectors | No extra DOM nodes, simple matching | Single reflow on style change | Lower paint cost | [OK] Good |