rem

A size measured from the font size set on the page's html element.

Safe to useBaseline: widely available

First version with support, from MDN browser data
BrowserSince
Chrome4+
Chrome Android18+
Edge12+
Firefox3.6+
Firefox Android4+
Safari5+
Safari iOS4+

Formula 1rem = font-size of :root (16px unless the reader changed the browser default)

How it works

1rem is the font-size of the html element, the root of the page. By default that is 16px, and a reader who raises the default size in the browser settings changes it for every rem on the page at once. So rem is the unit for type and spacing that should respect the reader: one setting scales the whole design, and a stylesheet that never touches the root size gets it for free.

Two details catch people out. In the root element’s own font-size, rem cannot refer to itself, so it reads the browser’s initial value instead: html { font-size: 2rem } gives 32px at the default size and 48px when the reader’s default is 24px. And in a media query rem behaves like em: it means the initial size and ignores whatever your CSS sets on html.

Two root sizes were measured with the reader’s default raised to 24px. html { font-size: 62.5% }, the old trick that makes 1rem 10px for easier arithmetic, gave 15px: a percentage is taken of the reader’s default, so the setting survives. The cost moves elsewhere: a body rule has to set the text size again, and every rem on the site reads as tenths. html { font-size: 16px } gave 16px: the pixel value replaces the reader’s default instead of scaling it, and the setting is gone for every rem on the page.

Try it

Measure the font-relative units

Pick a font and a size. The page measures 1em, 1ex, 1ch, 1cap and 1lh in that font, here, in your browser.

UnitMeasuredShare of the font size
1em
1ex
1ch
1cap
1lh
The same as a table
What each font-relative unit measures
UnitMeasures
1emThe font size of the element.
1exHow tall the letter x is in this font.
1chThe width of the digit zero in the font.
1capThe height of a capital letter in the font.
1lhThe line height of the element.

What changes it

Moves with
  • the reader's text size
  • page zoom
Stays put under
  • the window size
  • the font in use
  • the query container
  • phone toolbars
  • the writing mode

Reach for it when

Type sizes and the spacing between blocks, so that one browser setting scales the whole page.

Watch out

Setting the root size in pixels (say, 16px on html) switches off the reader's preference: rem then stays at 16px whatever the browser setting says. Leave the root alone or use a percentage.

Example No root size in px, and the heading follows the reader's setting along with its margin.

Before

html { font-size: 16px; }
h1 {
  font-size: 32px;
  margin-block-end: 24px;
}

After

h1 {
  font-size: 2rem;
  margin-block-end: 1.5rem;
}

MDN (opens in a new tab)Specification (opens in a new tab)