Performance: Theme implementation basics
MEDIUM IMPACT
This affects page load speed and rendering performance by how CSS variables and theme styles are applied and recalculated.
:root { --bg-color: white; --text-color: black; }
body { background-color: var(--bg-color); color: var(--text-color); }
body.dark-theme { --bg-color: black; --text-color: white; }body { background-color: white; color: black; } /* for light theme */
body.dark-theme { background-color: black; color: white; }| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Multiple CSS class toggles for theme | Minimal DOM changes | Multiple reflows triggered | High paint cost due to many property changes | [X] Bad |
| CSS custom properties for theme colors | Minimal DOM changes | Single reflow triggered | Lower paint cost with efficient repaint | [OK] Good |