liveBook · Manning

Relative unit

As explained in Architecting Accessibility

A relative measurement unit specifies a size in relation to another value, such as a parent dimension, root size, or viewport.

A relative unit sets a CSS size in relation to another value. Units such as em, rem, and % help text and spacing adapt when users change text size or zoom. section 4.4.1

For text that needs to remain usable when someone enlarges browser or operating-system text, prefer relative units over fixed px values. Let the root font size follow the browser default, size other text relative to it, and use responsive container constraints such as max-width. section 4.4.1

:root { font-size: 100%; } #A
body { font-size: 1rem; } #B
h1 { font-size: 2rem; } #C

This CSS example keeps the root size at the browser default and sizes body text and headings in rem. section 4.4.1

How Architecting Accessibility covers it

How deep it goes
Explains em, rem, and percentages for fonts and spacing, then demonstrates rem-based sizing alongside fixed-pixel styling.
Examples
Contrasts rem-based root, body, and heading rules with fixed-pixel body and heading sizes.
What you can do after
Apply relative CSS units to size text and spacing while supporting user font preferences and adaptable containers.
How it connects
Connects CSS font sizing with text scaling, browser zoom, and user font-size preferences.

Also explained in

Compare how 2 books explain relative unit →

Related concepts

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