GuideUpdated

rem vs em: what’s the difference, and which to use

rem is relative to the root font size, em to the element’s own. How each works, why em compounds, a px to rem table, and when to use rem, em or px.

rem and em are both relative CSS units. 1rem is the font size of the root element (html), which is 16px in browsers unless the page or the reader changes it. 1em is the font size of the current element, and for the font-size property itself, the font size of its parent. So a rem is the same size everywhere on the page, while an em grows and shrinks with the text around it.

The short answer

  • rem for font sizes and the spacing scale, so sizes stay predictable and follow the reader’s font size setting.
  • em for things that should scale with their own text: a button’s padding, an icon next to a label, letter-spacing.
  • px for borders, hairlines and anything that should stay fixed.

How rem works

A rem value is the pixel size divided by the root font size. With the usual 16px root, 1.5rem is 24px and 0.875rem is 14px, wherever the element sits in the page:

pxrem (16px root)
12px0.75rem
14px0.875rem
16px1rem
18px1.125rem
20px1.25rem
24px1.5rem
32px2rem
48px3rem

If a site sets html { font-size: 62.5% }, the root becomes 10px and 1.6rem is 16px. The math is easier, but every rem value on that site now means something different from the usual 16px base.

How em works, and why it compounds

An em looks at its own element. A button with font-size: 1rem; padding: 0.5em 1em gets 8px by 16px of padding; give it font-size: 1.25rem and the padding grows to 10px by 20px with no other change. That is what em is good at.

The catch is nesting. For font-size, em is relative to the parent, so sizes multiply. A list with font-size: 0.8em inside another one with the same rule ends up at 16 × 0.8 × 0.8 = 10.24px. rem doesn’t have this problem, which is why most design systems set font sizes in rem.

rem vs em vs px

remempx
Relative toThe root font sizeThe element’s font size (the parent’s, for font-size)Nothing: a fixed CSS pixel
Follows the reader’s default font size settingYesYesNo (page zoom still scales it)
Compounds when nestedNoYes, for font-sizeNo
Good forFont sizes, spacing scale, layout widthsPadding and icons that scale with their text, letter-spacingBorders, shadows, hairlines

Which one to use

  • Set the type scale in rem: body text 1rem, headings 1.5-3rem. It reads the same in every component.
  • Use em inside components whose spacing should follow their text size, such as buttons, badges and tags.
  • Keep px for 1px borders and fine details, where scaling would make lines blurry or uneven.
  • Avoid setting the root size in px (html { font-size: 16px }): it overrides the reader’s default font size setting for the whole page.

See the rem values on any website

When you study another site’s typography, its CSS might use px, rem or em, and DevTools shows the computed value in px. FontMeter can show every size in the unit you think in:

  1. Add FontMeter to Chrome and turn it on for the page.
  2. In its settings, set Units to rem. The size labels and the panel switch to rem, calculated from that page’s own root font size. pt is there too.
  3. In the Scale tab, Copy CSS, Tailwind or JSON tokens copy the page’s type scale with every size in rem.

See every font on a page in one click.

FontMeter is free. Add it to Chrome, open any page and press Alt+Shift+F. On Microsoft Edge? Get it from Edge Add-ons.

Add to Chrome, it’s free

More guides