Performance: Declaring variables
LOW IMPACT
Declaring CSS variables affects how styles are computed and reused, impacting style calculation and paint performance.
:root { --primary-color: #3498db; }
.button { color: var(--primary-color); background-color: var(--primary-color); border-color: var(--primary-color); }:root { }
.button { color: #3498db; background-color: #3498db; border-color: #3498db; }| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Repeating literal values | Minimal | Minimal | Higher due to repeated style calculations | [X] Bad |
| Using CSS variables | Minimal | Minimal | Lower due to reuse of computed values | [OK] Good |