Performance: Why CSS variables are used
MEDIUM IMPACT
CSS variables affect how styles are applied and updated, impacting rendering speed and layout stability.
:root { --main-color: #3498db; } .btn { color: var(--main-color); } .header { background-color: var(--main-color); }:root { --main-color: #3498db; } .btn { color: #3498db; } .header { background-color: #3498db; }| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Repeated hardcoded values | Minimal | Multiple on updates | Moderate | [X] Bad |
| Using CSS variables | Minimal | Single on variable change | Lower | [OK] Good |