Performance: Variable scope
MEDIUM IMPACT
Variable scope in CSS affects how and where custom properties (variables) are applied, impacting style recalculations and rendering performance.
.card { --main-color: blue; --accent-color: orange; } .card .button { color: var(--main-color); }
:root { --main-color: blue; --accent-color: orange; } .button { color: var(--main-color); }| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Global CSS variables | Low DOM ops | High reflows on variable change | High paint cost if many elements use variables | [X] Bad |
| Scoped CSS variables | Low DOM ops | Low reflows limited to container | Lower paint cost due to limited scope | [OK] Good |