Performance: Number types and units
MEDIUM IMPACT
How CSS number units affect layout calculations and rendering speed.
$width: 50%; $margin: 1.25rem; .element { width: $width; margin: $margin; }
$width: 100px; $margin: 20px; .element { width: $width; margin: $margin; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Fixed px units | No extra DOM nodes | Multiple reflows on resize | Moderate paint cost | [X] Bad |
| Relative units (%, rem) | No extra DOM nodes | Single reflow on resize | Lower paint cost | [OK] Good |