liveBook · Manning

Em

As explained in Web Design Playground

A CSS font-relative length unit whose computed size is based on the font size of the element or its context.

The em is a flexible CSS length unit for sizing text. Instead of locking everyone to pixels, it scales with the font size supplied by the browser, the user, or the element’s context. section 14.7 section 7.11

Let the reader choose the scale

If the relevant default font size is 16px, 1.5em becomes 24px and 3em becomes 48px. If the default is 24px, those same values become 36px and 72px. section 14.7

Keep these three ideas in mind:

  • em is relative, so it respects changes users make to their browser’s default text size. section 14.7 section 7.11
  • The font-size property inherits. An em value on a child is therefore calculated from the size established by its context, not always directly from the browser default. section 14.7
  • Do not confuse the em unit with the HTML em element, which emphasizes text. section 7.11
body {
    font-size: 1em;
}
header {
    font-size: 1.5em;
}
h1 {
    font-size: 2em;
}

Try the body, header, and h1 rules together, then follow how inherited font sizes affect nested em values. section 14.7

A useful takeaway: use relative typography when the page should adapt to different readers and screens, while remembering that nested em values can grow through inheritance. section 14.7 section 7.11

How Web Design Playground covers it

How deep it goes
Defines relative sizing and demonstrates inherited font-size calculations, but stops short of a broader CSS inheritance treatment.
Examples
Uses 1.5em and 3em conversions plus nested body, header, and h1 rules to illustrate scaling and inheritance.
What it assumes
Assumes basic CSS declarations and HTML nesting while explaining relative measurement and font-size inheritance.
What you can do after
Apply em values to create typography that follows browser defaults and user-selected text sizes.
How it connects
Connects em with font-size, inheritance, relative units, pixels, rem, percentages, and responsive typography.

Also explained in

Compare how 4 books explain em →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Web Design Playground. The section links point to the parts of the book it draws on.