How to Convert PX to REM in CSS
The px-to-rem formula, plus what we measured in Chromium when a reader raises their default font size from 16px to 20px: px text stays put, rem scales, 62.5% still scales, a px root locks it, and media queries ignore your root size.
The Conversion Formula
rem = px ÷ root font size. With the browser's usual 16px default: 24px = 1.5rem, 14px = 0.875rem, 48px = 3rem. If your stylesheet sets a different root size, divide by that instead; the PX to REM Converter takes any base. Common values at a 16px base: 10px = 0.625rem, 12px = 0.75rem, 18px = 1.125rem, 20px = 1.25rem, 32px = 2rem, 64px = 4rem.
The 16px figure is a browser default, not a fixed rule. MDN's definition of rem puts it plainly: a common default is 16px, "but user-defined preferences may modify this". That is the whole reason to use rem.
What Happens When a Reader Changes Their Font Size
We set Chromium's default font size (the setting in Chrome under Appearance, Font size) to 16px and then 20px, applied with the DevTools protocol, and read the computed sizes on a test page (October 13, 2026; script in our test folder).
| Stylesheet | User default 16px | User default 20px |
|---|---|---|
font-size: 16px on text | 16px | 16px: ignores the setting |
font-size: 1rem, no root size set | 16px | 20px |
padding: 1.5rem | 24px | 30px |
html { font-size: 62.5% }, then 1rem | 10px | 12.5px: still scales |
html { font-size: 16px }, then 1rem | 16px | 16px: locked |
@media (min-width: 40rem) at a 700px window | matches (40rem = 640px) | no match (40rem = 800px) |
Three findings. Text sized in px does not follow the reader's font setting, while rem does. The often-criticized 62.5% trick does not break that scaling, because a percentage is a share of the user's own default; what breaks it is setting the root in pixels (html { font-size: 16px }), which some resets do. And media queries ignore your root font size: a rem or em in a media query is measured against the browser's initial font size, so with the 62.5% root, 40rem in a query is still 640px, not 400px. The Media Queries specification defines this.
Note the other route to larger text: browser zoom (Ctrl or Cmd and +) enlarges px and rem alike, so a px layout survives zoom. The font-size setting is the case px fails, and some readers rely on it instead of zoom. WCAG 2.2 success criterion 1.4.4 requires text to resize to 200% without loss of content or function; using rem for type and spacing makes both routes work.
When to Use px, rem and em
- rem for font sizes, spacing and widths that should grow with the reader's text size.
- em for spacing inside a component that should follow that component's own font size, such as the padding of a button whose text size changes.
- px for hairline borders and shadows, where a 1px line should stay thin. On high-density screens one CSS pixel is several device pixels, and some widths such as borders are rounded to whole device pixels (MDN).
- rem or em in media queries if you want breakpoints to move when the reader picks a larger default, as the 20px row above shows.
Setting the Root Font Size
The safest choice is to leave the root alone, or set it as a percentage:
html { font-size: 100%; } /* = the reader's default */
body { font-size: 1rem; }
If you prefer the 62.5% shorthand so that 1.6rem means 16px, it still respects the reader's setting, but remember to set body { font-size: 1.6rem } or text falls to 10px, third-party components written for a 16px root will come out smaller, and media-query rem values will not match your 1rem = 10px arithmetic. Never set the root in px.
Frequently Asked Questions
How do I convert pixels to REM?
Why should I use REM instead of PX?
What is the default root font size?
- [1]MDN, <length>: rem and absolute length units (via MDN connector), checked Oct 13, 2026 ↗
- [2]W3C, Media Queries Level 4, section 4.1 Units (relative units use initial values), checked Oct 13, 2026 ↗
- [3]W3C, Understanding WCAG 2.2 Success Criterion 1.4.4 Resize Text, checked Oct 13, 2026 ↗
- [4]Chrome DevTools Protocol, Page.setFontSizes (method used in our test) ↗
