Educational guide to font-size
Choose a size and its reference
Compare units, inheritance, and keywords. Build a fluid scale and check how it responds when text is enlarged.
Mental model
font-size sets the nominal font size. Two families at the same size can look different: the visible height of letters depends on their metrics. The property inherits; line-height controls the line box.
- Root: 16 px in this diagram
1.25rem references the root: 1.25 × 16 = 20 px.
- Parent: 20 px in this diagram
1.25em and 125% in font-size reference the parent: 1.25 × 20 = 25 px.
- The computed value is inherited
Without a new declaration, a child inherits its parent’s computed size. Inheritance alone does not multiply the relative expression again.
Absolute and relative units
rem keeps a shared reference to the root; em and % in font-size let a component depend on its parent. px is an absolute length in CSS pixels, which do not necessarily match physical pixels.
A 1.25rem parent and five ways to size text
inherit · Text to read
1.25em · Text to read
125% · Text to read
1.25rem · Text to read
20px · Text to read
A px value can grow with page zoom even when it does not follow the default font size. Physical units such as pt (1 pt = 1/72 in) are absolute too. Start with relative units for screen reading. Outside font-size, em usually references the element’s own size; in font-size it uses the parent’s.
Inheritance and compounding
Inheriting a size preserves its computed value. Declaring 1.25em or 125% again at every level does apply another factor. rem keeps the same reference regardless of HTML depth.
The same rule applied at two levels
1.25em
First level
Second level
125%
First level
Second level
1.25rem
First level
Second level
Use em when you intend that local relationship. For a stable scale across components, rem avoids multiplication through nesting. A font-size percentage is based on the parent’s font size even if its box width changes.
Browser keywords
xx-small, x-small, small, medium, large, x-large, xx-large, and xxx-large are absolute sizes on a scale based on the user’s default size. Here, “absolute” does not mean a fixed pixel number. larger and smaller are relative to the parent.
An x-large parent and three sizing choices
inherit (x-large) · Text to read
medium · Text to read
larger · Text to read
smaller · Text to read
Do not assume medium always equals 16 px or that larger adds a fixed amount. initial restores medium, while inherit takes the parent’s computed size. The final appearance also depends on the font and browser settings.
Fluid sizing with bounds
clamp(minimum, preferred, maximum) lets text grow with the viewport between two bounds. This example combines rem with vw and keeps body text at 1rem. The preview panel’s width is not the viewport.
A fluid heading and body text tied to the root
Read at your own pace
Body text keeps a stable reference while the heading adapts to the window.
With a 16 px root, the heading ranges from 24 to 28 px. The bounds also grow with the root. However, the viewport term can offset some zoom: including rem does not guarantee effective 200% enlargement. Test several widths and zoom levels; if text cannot reach the required size, reduce the fluid part or use rem.
Preferences and text resizing
Let the root keep the size chosen by the browser; these recipes do not set font-size on html. One rem does not always mean 16 px. Increasing the default font, resizing text only, and page zoom are different checks.
Check that text can be enlarged to 200% without losing content or actions. Also check reflow at 320 CSS pixels, equivalent in width to a 1280 px window at 400% zoom. That width equivalence does not replace testing real zoom.
Let containers grow and labels wrap; avoid fixed heights and clipping. Keep line-height unitless and browser zoom available. Test size preferences in the actual browser and device: changing the root in developer tools checks only part of the behavior.
Common pitfalls
Each level looks larger
- Expected result
- Nested components keep a predictable scale.
- Cause
- The same rule with em or % is reapplied at every level.
- Solution
- Declare the size once and let children inherit, or use rem when they need a shared reference.
Text barely grows when zooming
- Expected result
- The user can reach effective 200% text enlargement.
- Cause
- A size dominated by vw shrinks in CSS pixels as zoom narrows the viewport.
- Solution
- Combine a relative base with relative bounds; check effective growth at several widths. Use rem if the formula prevents it.
Letters or actions are clipped
- Expected result
- Enlarged text remains complete and operable.
- Cause
- A fixed height, insufficient line spacing, or clipping prevents the box growing.
- Solution
- Allow automatic height and wrapping; review line-height and overflow alongside the font size.
Support and compatibility
The units and keywords shown and the three-argument form of clamp() are Baseline Widely Available. Syntax support does not establish that a particular scale respects preferences or zoom.
This guide covers the playground’s values and an additional fluid recipe; it does not extend that availability to every new font-size value. Preferences, minimum sizes, and automatic text enlargement may affect the result. Check actual reading as well as the computed value.