Design Tools

px vs rem: why your font sizes should be allowed to scale

Pixels are fixed. Rem units follow the reader's own text size. The switch takes one division by 16, and it quietly makes your site usable for everyone who has changed their browser's font size.

By the Toolcloak team8 October 20263 min read
In this article
  1. What a rem is
  2. What happens when the reader changes their size
  3. rem, em and px side by side
  4. The 62.5% trick, and why to skip it

Someone with poor eyesight raises their browser's default text size to 24 pixels. Your page, with every font set in px, ignores it. A page built with rem does not. That is the whole argument, and it fits in one sentence.

What a rem is

A rem is relative to the font size set on the root element (the html tag). Browsers default that to 16px, so 1rem is 16px, 2rem is 32px and 0.5rem is 8px. If a reader changes their browser's text size, the root changes, and everything in rem moves with it.

Common pixel sizes in rem (16px root)
0.7512px0.87514px116px1.2520px1.524px232px

16px, the browser default, is exactly 1rem. Body text usually sits there.

Type a pixel value and a root size and get the rem value, or go the other way.Open PX to REM Converter

What happens when the reader changes their size

A reader sets their browser text to 24px
Your text in pxstays 16px
  • Their setting is ignored
  • Hard to read for people who set it on purpose
Your text in rembecomes 24px
  • 1rem × 24 = 24px
  • Layout, headings and spacing grow in step

Many people change their browser or phone text size on purpose. Respecting it costs you nothing.

rem, em and px side by side

UnitRelative toGood for
pxNothing: a fixed sizeHairline borders, shadows, icons that must not scale
remThe root font sizeFont sizes, margins and padding, media-query widths
emThe parent's font sizeSpacing that should follow its own element's text, such as button padding

The trap with em is nesting: an em inside an em compounds, so 1.2em in a 1.2em parent is 1.44 times the base.

The 62.5% trick, and why to skip it

Some developers set html { font-size: 62.5% } so that 1rem equals 10px, making the maths easier. It works, but it quietly overrides the user's default and can shrink text for people who raised it. Divide by 16 in your head, or let a tool do it, and leave the root alone.

  1. Leave the root at the default. Do not set html to a px value.
  2. Write font sizes in rem. 1rem for body, 1.25rem for lead text.
  3. Use px for borders and shadows. A 1px line should stay 1px.
  4. Test with a bigger default. Raise your browser's text size once and see what breaks.
  5. Think of the viewport as well. For fluid headings, try clamp() with rem bounds.

Questions people ask

How do I convert px to rem?

Divide the pixel value by the root font size, which is 16 by default. 24px divided by 16 is 1.5rem.

What is the difference between rem and em?

rem is relative to the root font size, so it is predictable everywhere. em is relative to the parent element's font size, so nested ems compound.

Should I use px or rem for font size?

Use rem, so text respects the user's browser settings. Keep px for things that should not scale, like thin borders.

Is 1rem always 16px?

Only when the root font size is the default 16px. If the user or your CSS changes the root size, 1rem changes with it.

Does using rem help accessibility?

Yes. People who set a larger default font size get a page that scales with their choice, instead of one that ignores it.