Performance: Dynamic inline styles
MEDIUM IMPACT
Dynamic inline styles affect rendering speed and layout stability by causing style recalculations and potential layout shifts when styles change frequently.
<div class:colored={color === 'red'} style="font-size: {fontSize}px;"></div> <style> .colored { color: red; } </style>
<div style="color: {color}; font-size: {fontSize}px; margin-left: {margin}px;"></div>| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Frequent dynamic inline styles on size/position | Low (single element) | Multiple reflows per update | High paint cost due to layout changes | [X] Bad |
| Mostly CSS classes with minimal inline styles | Low | Single reflow or none | Lower paint cost | [OK] Good |