Performance: CSS custom properties vs SASS variables
MEDIUM IMPACT
This concept affects how CSS values are processed and updated in the browser, impacting rendering speed and dynamic style changes.
:root {
--primary-color: #3498db;
}
.button {
background-color: var(--primary-color);
}
// Can change --primary-color dynamically with JavaScript without reload$primary-color: #3498db; .button { background-color: $primary-color; } // To change color dynamically, need to recompile CSS
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| SASS variables (static) | None at runtime | 0 | Minimal | [OK] Good for static styles |
| CSS custom properties (dynamic) | None unless JS changes styles | 0-1 per change | Low if used for paint-only properties | [!] OK with dynamic updates |