Performance: CSS custom properties (variables)
MEDIUM IMPACT
CSS custom properties affect style calculation and paint stages, influencing how quickly styles update and how stable the layout remains.
:root { --main-color: blue; } .button { color: var(--main-color); } /* Change --main-color to update all */:root { --main-color: blue; } .button { color: blue; } /* Changing color by updating all selectors */| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Hardcoded colors in many selectors | None | Multiple reflows if layout changes | High paint cost on updates | [X] Bad |
| Using CSS custom properties for colors | None | Single reflow if layout unaffected | Low paint cost on updates | [OK] Good |