Building it

PX vs REM vs EM in CSS: Which Unit to Use

What px, rem and em resolve against, what happens when a reader enlarges the browser font size or zooms, and where each unit still belongs in real CSS.

Two browser windows with the same blocks at two sizes and a ruler between them

Use rem for font sizes, spacing and layout widths, px for hairline borders, shadows and other details that should never grow, and em only when a component should scale with its own text. That is the short answer. The rest of this guide shows why, with real renders from Chromium rather than diagrams, so you can see exactly what each unit does when a reader changes their browser settings.

What each unit resolves against

Every CSS length ends up as pixels on the screen. The difference between units is what they are measured against before that happens.

UnitResolves against1 unit at default settingsChanges when the reader enlarges text
pxNothing (an absolute CSS pixel)1pxNo
remThe font size of the root html element16pxYes
emThe font size of the current element (for font-size, the parent)Depends on contextYes
%The parent, for the property in questionDepends on contextFor font-size, yes
vw, vh1% of the viewport width or height3.6px on a 360px phoneNo

A CSS pixel is not a hardware pixel. On a phone with a device pixel ratio of 3, one CSS pixel is drawn with three device pixels across. That is why px is safe for crisp details on any screen, and also why it says nothing about how large the reader wants their text to be. (If you want to see how a physical screen maps to pixels, the PPI Calculator works it out from resolution and diagonal size.)

The rem unit, short for "root em", was added so you could size things relative to one predictable number: the root font size. Unless your stylesheet changes it, that number comes from the browser, and the browser takes it from the reader's settings. The definitions are in the CSS Values and Units specification.

What happens when a reader changes the browser font size

This is the case that decides the whole argument. Chrome, Edge and Firefox all let a person change the default font size in their settings. In Chrome the options are Very small, Small, Medium (the default, 16px), Large (20px) and Very large (24px). People with low vision use this setting, and so do plenty of people who simply find 16px too small on a large monitor.

Here is the same paragraph twice, once set in px and once in rem, rendered at the default 16px and again with the browser default set to 24px:

Two paragraphs in px and rem at browser font sizes of 16px and 24px
Rendered in Chromium with the browser default raised from 16px to 24px. The 1rem paragraph follows the reader to 24px; the 16px paragraph stays exactly where the stylesheet put it.

The px paragraph ignores the reader completely. The rem paragraph does what the reader asked for. Nothing else in the CSS changed.

That matters for more than courtesy. WCAG 2.2 success criterion 1.4.4, Resize Text, is a Level AA requirement: text must be resizable up to 200 percent without assistive technology and without losing content or function. Browser zoom usually satisfies that on its own, but the font size setting is the gentler tool many readers prefer, because it enlarges text without blowing up every image and margin. A site sized in px quietly removes that option.

What happens on page zoom

Zoom is different. When someone presses Ctrl and plus (or Cmd and plus), the browser makes every CSS pixel bigger. Both units scale:

The same px and rem headings at 100 percent and 200 percent page zoom
Page zoom scales every CSS pixel, so 24px and 1.5rem both draw at 48 screen pixels at 200 percent. Zoom is not where the two units differ; the font size setting is.

At 200 percent zoom, 24px and 1.5rem both render at 48 device pixels. Zoom also shrinks the viewport in CSS pixels (a 600px window at 200 percent behaves like a 300px one), so media queries fire and the layout reflows to its narrow version.

So the honest summary is:

  • Zoom: px and rem both scale. Neither is better.
  • Browser font size setting: rem scales, px does not.
  • Viewport units: a vw size scales with neither, which is why pure vw font sizes are an accessibility bug. The sibling guide on responsive font sizing in CSS measures that problem and shows the clamp() pattern that fixes it.

Where px is still the right unit

Using rem everywhere is not the goal. Some things should stay exactly the size you drew them, even when the reader asks for bigger text.

Borders and hairlines. A 1px divider is meant to be the thinnest visible line. Convert it to 0.0625rem and it becomes 1.5px at a 24px default, which some browsers round unevenly, so a grid of cards ends up with lines of different weights. Keep border: 1px solid in px.

Box shadows and outlines. A shadow offset of 0 2px 6px describes a material effect, not content. Growing it with the text adds blur without adding meaning. The Box Shadow Generator outputs px for exactly this reason. Focus outlines are an exception worth a thought: a 2px focus ring is fine, but do not make it thinner than that.

Small decorative details. Icon stroke widths, border radii on small controls and the size of a decorative dot can stay in px.

Media query breakpoints: the real debate. This one splits teams, and it is worth knowing why. The Media Queries specification says relative units in a media query are based on the initial font size, which is the browser default, not your html rule. So @media (min-width: 48em) means 768px for most people but 1152px for a reader whose default is 24px. That is often what you want: someone with enlarged text gets the single-column layout sooner, before long words start breaking out of narrow columns. A px breakpoint ignores the setting and keeps the multi-column layout while the text inside it grows. Our position: use em breakpoints for layouts driven by text (articles, forms, navigation), and accept px breakpoints only where the layout is driven by images or fixed-size media. Either way, test with the browser font size set to Very large.

Where rem is the right unit

Font sizes. All of them. Body copy, headings, labels, buttons, captions. This is the one rule worth enforcing in code review.

Spacing around text. Padding inside buttons and cards, margins between paragraphs, gaps in a grid of text blocks. If the text doubles but the padding stays at 12px, the button turns into a cramped box with letters touching its edges.

Readable widths. A max-width: 40rem on an article keeps lines at a comfortable length whatever size the reader picks. The same limit in px turns into a narrow ribbon of four words per line at a large setting.

Component heights that hold text. Inputs, buttons and table rows with a fixed height: 40px clip their text when it grows. Use min-height in rem, or let padding set the height.

If your current stylesheet is all px, converting it does not need to be a rewrite. The PX to REM Converter gives any value at any root size, and the companion guide on the CSS root font size and px to rem conversion walks through a safe conversion with a regex and PostCSS, including what not to convert.

Where em still earns its place

Because em is relative to the current element, it compounds. Set list items to 0.85em, nest the list three levels deep, and each level shrinks again:

Nested list sizes shrinking with em and staying constant with rem
Measured computed sizes. With 0.85em each level multiplies the one above it, falling from 13.6px to 8.35px by the fourth level, while 0.85rem holds 13.6px at every depth.

That is the classic em bug, and it is why rem replaced em as the default. But compounding is exactly what you want in a few places:

  • Padding and icon sizes inside a component that comes in several text sizes. Give a button padding: 0.5em 1em and an icon width: 1.25em, then set only font-size on the small and large variants. Everything inside scales together.
  • Inline elements such as code, sup and small, which should be sized relative to the sentence they sit in, not to the root.
  • Letter spacing, which reads best as a fraction of the font size: letter-spacing: 0.02em.

The rule of thumb: use em inside a component, rem between components.

Where % and viewport units come in

Percentages behave like em for font-size (font-size: 120% equals 1.2em), so the same compounding applies. For widths, % is relative to the parent's width and is the right tool for fluid columns: width: 50% inside a grid cell.

Viewport units (vw, vh, vmin, the newer svh and dvh) are right for layout pieces tied to the screen: a full-height hero, a gutter that grows with the window. They are wrong as a font size on their own, for the zoom reason above. Mixed into clamp() with a rem part, they are how modern fluid type works.

The 62.5% root trick, and its downside

Many stylesheets start with this:

CSS
html { font-size: 62.5%; }  /* 62.5% of 16px = 10px */
body { font-size: 1.6rem; } /* back to 16px */

The appeal is arithmetic: with a 10px root, 1.4rem is 14px and 2.4rem is 24px, no division needed. Because it is a percentage, it still respects the reader: at a 20px browser default the root becomes 12.5px and 1.6rem becomes 20px. That part is fine.

The downsides are practical:

  1. Every third-party component sized in rem shrinks. A date picker, chat widget or design system package that assumes a 16px root renders at 62.5 percent of its intended size, and you end up overriding it.
  2. Forgetting the body reset leaves any text without an explicit size at 10px, which is unreadable.
  3. Writing html { font-size: 10px } instead, which looks equivalent, breaks the reader's setting completely. That mistake is common enough that the root font size guide has a rendered comparison of both.

You do not need the trick for arithmetic any more. Keep the default 16px root and convert with the PX to REM Converter, or let a build step do it.

A quick test you can run today

  1. In Chrome, open Settings, Appearance, Font size, and choose Very large.
  2. Reload your site. Text set in px stays small; text in rem grows. Note anything that stays small, clips inside a fixed height or overlaps.
  3. Reset, then zoom to 200 percent with Ctrl and plus. Check that nothing is cut off and no horizontal scrollbar appears (that second check is WCAG 1.4.10, Reflow).
  4. While you are in there, check that enlarged text still meets contrast against its background with the Color Contrast Checker. Thin weights at large sizes sometimes pass where small ones failed, and the other way round.

Most sites fail step 2 somewhere, usually in a header, a button or a form label someone set in px years ago. Those are the lines to convert first.

The takeaway

  • rem for type, spacing and readable widths, because it follows the reader's font size setting.
  • px for borders, shadows and fine details that should not grow.
  • em inside a component when its parts should scale with its own text.
  • Never a bare vw font size; wrap it in clamp() with a rem part.
  • Keep the 16px root unless you have a strong reason, and never set the root in px.

If an audit like this turns up more than a handful of fixed sizes and clipped controls, it is the kind of work our website fixes and maintenance service measures and fixes at a fixed price.

Tools mentioned in this post

Services for this

See All Services

Want this built properly?

Send a written enquiry and we reply by email with questions. A call is optional, and free. Then you get the scope in writing and a fixed quote for the first phase.

What happens next

  1. You send a written enquiryTell us the problem.
  2. We reply by emailWith our questions.
  3. A written scope and quoteA call only if you want one.
Based inTamil Nadu, India
ProcessWritten first, a call only if you want one