Performance: Using variables
LOW IMPACT
Using CSS variables affects the style calculation and paint stages by enabling reuse of values without repeating code.
:root { --main-color: #3498db; }
.button { color: var(--main-color); }
.header { background-color: var(--main-color); }
.footer { border-color: var(--main-color); }:root { }
.button { color: #3498db; }
.header { background-color: #3498db; }
.footer { border-color: #3498db; }| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Repeating color values | None | Multiple style recalculations if changed | Moderate paint cost if styles change | [X] Bad |
| Using CSS variables | None | Single style recalculation on variable change | Lower paint cost due to fewer recalculations | [OK] Good |