Skip to content
Astera Technology

Avoid accidental font growth in nested content

Compare two nested 1.25em sizes with two nested 1.25rem sizes.

The em pair computes 20/25px; the rem pair computes 20/20px.

Download complete case notes and answer keys ↓

Inspect the working example

The root font is16px. The first pair uses 1.25em on outer and inner sections; the second pair uses 1.25rem on both.

Inputs and native observations
CaseInput or inspectionResult and meaning
Outer em16×1.2520px
Inner em20×1.2525px
Both rem levelsRoot 16×1.25 for each20px,20px
Download editable CSV ↓

Follow the browser mechanism

For font-size, em resolves against inherited font size; rem resolves against the root. The difference becomes visible under nesting. Neither unit is universally better: choose whether local relative growth or a root-based scale matches the task.

Replacing rem with em compounds the inner level

The contrast applies 1.25em to both levels where a root-based 20px pair was intended.

Counterexample source; inspect separately
<style>body{margin:8px}</style>
<style>html{font-size:16px}.root-relative{font-size:1.25em}</style><section class="root-relative">Outer<section class="root-relative">Inner</section></section>

Outer becomes 20px and inner 25px, rather than the intended 20px at both levels.

Try the repair

If the root becomes 20px, what sizes follow in the original working pairs?

Show the worked answer

em gives 25px then 31.25px; rem gives 25px at both levels.

  • Record root and both nested computed sizes.
  • Test the intended nesting rather than a single isolated element.

Original example files

Related resources