Performance: Why variables reduce repetition
MEDIUM IMPACT
Using variables reduces CSS file size and speeds up style recalculations by avoiding repeated values.
$primary-color: #3498db; .button { background-color: $primary-color; border: 1px solid $primary-color; color: white; } .link { color: $primary-color; }
$primary-color: #3498db; .button { background-color: #3498db; border: 1px solid #3498db; color: white; } .link { color: #3498db; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Repeated literal values | N/A | N/A | Higher due to larger CSS size | [X] Bad |
| Using variables for repeated values | N/A | N/A | Lower due to smaller CSS size | [OK] Good |