Performance: Font size
Font size affects the rendering speed and layout stability of text content on the page.
Jump into concepts and practice - no test required
html { font-size: 100%; } body { font-size: 1rem; } h1 { font-size: 2rem; } p { font-size: 0.875rem; }body { font-size: 16px; } h1 { font-size: 32px; } p { font-size: 14px; }| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Fixed pixel font sizes | Minimal | Multiple on resize/zoom | Moderate | [X] Bad |
| Relative font sizes (rem, em) | Minimal | Single or none on resize | Low | [OK] Good |
font-size control on a webpage?font-sizefont-size property in CSS sets how big or small the text appears on the screen.p { font-size: 2rem; }remrem means "root em" and is relative to the root (html) font size.2remrem units scale relative to root font size [OK]h1 { font-size: 20; }p { font-size: ?; }px is fixed and doesn't scale with user changes. em and % are relative to parent and can compound in nesting. rem is relative to root font size, scaling perfectly with user settings.1.2rem increases size by 20% relative to root, ideal for accessibility and responsiveness.rem units scale with root font size and user settings [OK]