When you're building a website or styling text, controlling font size is one of the most fundamental decisions you'll make. HTML itself doesn't set size—that's the job of CSS (Cascading Style Sheets). Understanding the different methods available and how they behave helps you make choices that work for your specific design goals.
Font sizes work on a spectrum between absolute units (fixed sizes that don't change) and relative units (sizes that scale based on a parent element or user settings). This distinction matters because it affects readability, accessibility, and how your design adapts across devices.
Absolute units like pixels (px) give you precise control. A 16px font will always be 16 pixels, regardless of other factors. Relative units like em, rem, and percentages (%) scale based on other values in your design system, making them more flexible across different contexts and screen sizes.
Pixels are the most straightforward approach. You specify an exact size: font-size: 16px; means that text will be 16 pixels tall. Designers often favor pixels because they're predictable and easy to measure.
The trade-off: pixels don't scale automatically. If a user has set their browser to a larger default font size for readability, pixel-based sizing ignores that preference. This can create accessibility concerns, particularly for users with low vision.
An em is relative to the font size of the element's parent. If the parent has font-size: 16px; and you set a child to font-size: 1.5em;, that child will be 24 pixels (1.5 × 16).
Em units are useful for scaling components proportionally—larger containers can have proportionally larger text inside them. The challenge: em values compound when nested. A child of a child of a child, each set to 1.5em, gets exponentially larger, which can create unexpected results if you're not careful with your cascade.
Rem (root em) fixes the nesting problem. It's always relative to the root element's font size (usually the <html> tag), typically 16px by default in browsers. So font-size: 1.5rem; is always 24 pixels, regardless of parent values.
Rem is widely considered a modern best practice because it's predictable, respects user browser settings, and scales consistently. Most developers use rem for main sizing and occasionally mix in em for component-specific scaling.
A percentage is relative to the parent element's font size. font-size: 150%; means 1.5 times the parent's size. Percentages behave similarly to em (in fact, 1em and 100% are equivalent in this context).
They're useful when you want text to scale proportionally with its container, but they share the same nesting-compounding issue as em.
HTML allows text keywords like font-size: large; or font-size: smaller;. These map to predefined sizes in the browser's stylesheet and are rarely used in modern web design because they offer less control and less predictability than units.
| Method | Relative To | Accessibility | Use Case | Nesting Issue |
|---|---|---|---|---|
| px | Fixed value | Poor (ignores user prefs) | Exact layouts, icons | No |
| em | Parent element | Good | Component scaling | Yes (compounds) |
| rem | Root element | Good | Main typography system | No |
| % | Parent element | Good | Proportional scaling | Yes (compounds) |
| Keywords | Browser defaults | Fair | Legacy only | No |
Device and responsiveness: If you're designing for multiple screen sizes, relative units adapt more naturally. Pixels require media queries to adjust.
Accessibility requirements: Users with visual impairments often increase their browser's base font size. Rem and em units respect this; pixels do not.
Design complexity: Simple layouts with consistent type may be fine with pixels. Complex nested components benefit from rem's predictability.
Team standards: Most modern projects standardize on rem for body text and strategic use of em for component-relative sizing, but every team has its own conventions.
The right method for your project depends on whether you're prioritizing exact control, responsive scaling, accessibility compliance, or a combination of these. Understanding the differences lets you make that choice intentionally.
