Performance: Typography scale generation
MEDIUM IMPACT
This affects page load speed and rendering performance by controlling how font sizes are calculated and applied across the site.
$font-size-base: 1rem; $scale-ratio: 1.25; @function type-scale($step) { @return $font-size-base * pow($scale-ratio, $step); } h1 { font-size: type-scale(3); } h2 { font-size: type-scale(2); } h3 { font-size: type-scale(1); } p { font-size: type-scale(0); }
$font-size-base: 16px; h1 { font-size: $font-size-base * 2.5; } h2 { font-size: $font-size-base * 2; } h3 { font-size: $font-size-base * 1.75; } p { font-size: $font-size-base; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Manual repeated font sizes | Minimal | Multiple reflows if sizes change dynamically | Medium paint cost due to text rendering | [X] Bad |
| Function-based scale generation | Minimal | Single reflow on load | Lower paint cost with consistent sizes | [OK] Good |
| Loop with runtime calculations | Minimal | Multiple reflows if recalculated often | Higher paint cost | [!] OK |
| Precomputed size list | Minimal | Single reflow | Lowest paint cost | [OK] Good |