Performance: Responsive typography scales
Responsive typography scales affect page load speed and rendering by controlling font size changes smoothly across devices without causing layout shifts.
$min-size: 1rem; $max-size: 1.25rem; $min-vw: 320; $max-vw: 1200; @function fluid-type($min, $max, $min-vw, $max-vw) { @return clamp(#{$min}, calc(#{$min} + (#{$max} - #{$min}) * ((100vw - #{$min-vw}px) / (#{$max-vw} - #{$min-vw}))), #{$max}); } body { font-size: fluid-type($min-size, $max-size, $min-vw, $max-vw); }
$font-size: 16px; body { font-size: $font-size; } @media (min-width: 768px) { body { font-size: 20px; } }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Abrupt font size changes at breakpoints | Minimal DOM changes | Multiple reflows on viewport resize | High paint cost due to layout shifts | [X] Bad |
| Fluid typography with clamp() or Sass calculations | Minimal DOM changes | Single reflow with smooth scaling | Low paint cost with stable layout | [OK] Good |
$min-font: 1rem;
$max-font: 2rem;
$min-screen: 320px;
$max-screen: 960px;
font-size: clamp(#{$min-font}, calc(1rem + (1vw - 3.2px) * 1.25), #{$max-font});$min-font: 1rem; $max-font: 2rem; font-size: clamp($min-font, calc(1rem + 1vw), $max-font);
Pass the test and this pattern moves unknown