CSS Root Font Size: Converting PX to REM
How the root font size turns rem into pixels, the formula both ways, the 62.5% trick and its catch, and a safe way to convert a px stylesheet to rem.

A rem is one root font size. Everything about converting between px and rem follows from that single sentence: what the root is, where its value comes from, and what happens when someone changes it. This guide gives the formula both ways, a reference table for the two roots people actually use, a tested process for converting an existing px stylesheet, and the mistakes that cause most rem bugs.
Where the root font size comes from
The root is the html element. Its font size is the number every rem multiplies.
If your CSS never sets it, the root font size is the browser default, which is 16px in every major browser at default settings. That default is not fixed, though. Readers can change it in their browser settings (Chrome offers Small, Medium, Large and Very large, where Medium is 16px and Very large is 24px), and the root follows. That is the reason to use rem at all: the sibling guide on px vs rem vs em in CSS shows the rendered difference.
If your CSS does set it, the root becomes whatever you wrote, resolved in one of two ways:
- As a percentage, em or rem, it is relative to the browser default.
html { font-size: 62.5% }gives 10px at a 16px default and 12.5px at a 20px default. - As px, it is fixed.
html { font-size: 10px }is 10px for everyone, whatever they chose.
That difference is the most important line in this guide, and the section on the 62.5% root below shows it rendered.
The conversion formula, both ways
px to rem: rem = px divided by root font size.
rem to px: px = rem times root font size.
At the default 16px root:
- 14px to rem = 14 / 16 = 0.875rem
- 20px to rem = 20 / 16 = 1.25rem
- 22px in rem = 22 / 16 = 1.375rem
- 24px to rem = 24 / 16 = 1.5rem
- 1.25rem to px = 1.25 times 16 = 20px
- 4rem to px = 4 times 16 = 64px
At a 10px root, the division is by 10, which is why the trick is popular: 14px is 1.4rem and 24px is 2.4rem.
For any other root (some design systems use 18px or 20px), divide by that number instead. The PX to REM Converter takes the root as an input and redraws its whole reference table for it. Here it is set to a 10px root:
Reference table: px to rem
| px | rem at 16px root | rem at 10px root |
|---|---|---|
| 1px | 0.0625rem | 0.1rem |
| 2px | 0.125rem | 0.2rem |
| 4px | 0.25rem | 0.4rem |
| 6px | 0.375rem | 0.6rem |
| 8px | 0.5rem | 0.8rem |
| 10px | 0.625rem | 1rem |
| 12px | 0.75rem | 1.2rem |
| 14px | 0.875rem | 1.4rem |
| 16px | 1rem | 1.6rem |
| 18px | 1.125rem | 1.8rem |
| 20px | 1.25rem | 2rem |
| 22px | 1.375rem | 2.2rem |
| 24px | 1.5rem | 2.4rem |
| 25px | 1.5625rem | 2.5rem |
| 28px | 1.75rem | 2.8rem |
| 30px | 1.875rem | 3rem |
| 32px | 2rem | 3.2rem |
| 36px | 2.25rem | 3.6rem |
| 40px | 2.5rem | 4rem |
| 48px | 3rem | 4.8rem |
| 50px | 3.125rem | 5rem |
| 56px | 3.5rem | 5.6rem |
| 60px | 3.75rem | 6rem |
| 64px | 4rem | 6.4rem |
| 72px | 4.5rem | 7.2rem |
| 80px | 5rem | 8rem |
Reference table: rem to px
| rem | px at 16px root | px at 10px root |
|---|---|---|
| 0.25rem | 4px | 2.5px |
| 0.5rem | 8px | 5px |
| 0.75rem | 12px | 7.5px |
| 0.875rem | 14px | 8.75px |
| 1rem | 16px | 10px |
| 1.125rem | 18px | 11.25px |
| 1.25rem | 20px | 12.5px |
| 1.5rem | 24px | 15px |
| 1.75rem | 28px | 17.5px |
| 2rem | 32px | 20px |
| 2.5rem | 40px | 25px |
| 3rem | 48px | 30px |
| 4rem | 64px | 40px |
| 5rem | 80px | 50px |
Both tables assume the reader has not changed their browser default. The moment they do, the 16px column moves with them, which is the point.
The 62.5% root and the 100% root
The 100% root is no rule at all, or html { font-size: 100% } written out to make the intent explicit. One rem is the reader's default, 16px for most people. Every third-party component that uses rem renders at the size its authors intended. This is the root we recommend.
The 62.5% root sets the root to 10px at default settings so the arithmetic becomes a decimal shift. It needs a reset so unstyled text is not tiny:
html { font-size: 62.5%; } /* 10px at a 16px default */
body { font-size: 1.6rem; } /* 16px at a 16px default */How html { font-size: 62.5% } interacts with user settings
Because 62.5% is a percentage, it is 62.5% of whatever the reader chose. We rendered three roots at the default 16px and again with the browser default raised to 20px:
At 20px, the 62.5% root becomes 12.5px and 1.6rem becomes 20px: the reader's choice survives. The 10px root stays 10px, and the same 1.6rem is stuck at 16px: the reader's choice is thrown away, and with it the main benefit of rem. The 62.5% trick is accessible; the px version of it is not. If you inherit a stylesheet with html { font-size: 10px }, changing that one line to 62.5% is the cheapest accessibility fix you will make this year.
The trick's remaining costs are practical rather than accessibility ones: any widget, embed or package that assumes a 16px root renders at 62.5% of its intended size, and any element you forget to give a size inherits 10px text.
Converting an existing px stylesheet to rem
Do not convert everything. Borders, shadows and hairlines should stay in px (the px vs rem guide explains why), and breakpoints deserve their own decision. The goal is to convert font sizes, spacing around text and readable widths.
Step 1: decide the root and leave it alone
Keep the 16px default unless your codebase already uses 62.5% everywhere. Changing the root halfway through a project is how sites end up with two systems.
Step 2: convert by hand where the file is small
For a single component or a short stylesheet, look values up with the PX to REM Converter or the tables above. It processes everything in your browser, and the reference table means most common values need no typing at all.
Step 3: use a regex for a one-off conversion
In an editor that supports regex find and replace, this pattern matches px values:
Find: (\d*\.?\d+)pxMost editors cannot divide in a replacement, so run it as a small script instead. This one skips values below 2px, so 1px borders stay as they are:
const toRem = (css, root = 16) =>
css.replace(/(\d*\.?\d+)px\b/g, (match, n) =>
Number(n) < 2 ? match : `${+(n / root).toFixed(4)}rem`);
toRem(".a{margin:0 24px;font-size:14px;width:calc(100% - 32px);border:1px solid}");
// .a{margin:0 1.5rem;font-size:0.875rem;width:calc(100% - 2rem);border:1px solid}
We ran that exact line; the output is the comment below it. Notice it also converted the 32px inside calc(), which is usually right but worth a look. A regex cannot tell a shadow from a font size, so review the diff property by property before you commit it.
Step 4: use PostCSS for anything ongoing
For a project that keeps writing px, convert at build time with postcss-pxtorem so the source stays readable. We tested version 6.1.0 with a small stylesheet:
// postcss.config.js
module.exports = {
plugins: {
"postcss-pxtorem": {
rootValue: 16,
propList: ["*", "!border*", "!box-shadow"],
minPixelValue: 2,
},
},
};What we saw, so you know what to expect:
- With default options it converts only text properties:
font-size,line-height,letter-spacingandword-spacing. Padding and margin stay in px until you widenpropList. propList: ["*"]converts everything, which is why the negations for borders and shadows matter.minPixelValue: 2leaves1pxvalues alone everywhere.- Media queries are not converted unless you set
mediaQuery: true. - Uppercase
PXis ignored, soborder-bottom: 1PX solidis a handy opt-out for a single declaration.
Minify after conversion, not before; the CSS Minifier is fine for a quick check of the final size.
Step 5: test with a changed default
Set the browser font size to Very large and click through the site. Anything still small was missed; anything clipped has a fixed height in px. Then try page zoom at 200 percent. Both checks take five minutes and catch nearly every conversion bug.
The mistakes that cause most rem bugs
Setting the root in px. Covered above, and the one with real consequences for readers. Use a percentage.
Setting the root in rem to resize body text. html { font-size: 1.25rem } is legal: on the root, rem refers to the browser default, so it computes to 20px at default settings (we checked). But it also rescales every rem on the site, so all your spacing grows by a quarter along with the text. If you want larger body copy, set it on body and leave the root alone.
Mixing roots across components. A component written for a 10px root, dropped into an app with a 16px root, renders 60% too large: its 1.6rem becomes 25.6px. This happens with copied snippets, old design system packages and micro-frontends that share a page. Note that rem inside a shadow DOM still refers to the document's html, not the component's host. Pick one root for the whole page and convert anything that disagrees.
Forgetting line-height units. Converting line-height: 24px to 1.5rem keeps the problem it had: a fixed line height that does not follow the element's own font size. Worse is line-height: 1.5em on body, which computes to 24px once and passes 24px down to every child, so a 40px heading inherits 24px lines and its lines overlap. Use a unitless number, line-height: 1.5, which passes the ratio down instead. MDN's line-height reference describes the same behaviour.
Converting the wrong things. Rem borders turn 1px lines into fractional pixels at large settings. Shadows in rem grow blurrier with the text. Keep the values from tools like the Box Shadow Generator in px.
Rounding too early. 0.6875rem is 11px exactly. Rounding it to 0.69rem gives 11.04px, and across a type scale the small errors stack up into inconsistent spacing. Four decimal places is plenty.
The takeaway
- rem = px divided by the root; px = rem times the root. At the default root, divide or multiply by 16.
- Leave the root at the browser default, or use a percentage. Never px.
- Convert type, spacing and widths; keep borders and shadows in px.
- Use the converter for a handful of values, a script for a one-off file and PostCSS for a living codebase, then test with the browser font size raised.
For fluid sizes that grow with the screen as well as the reader, continue with responsive font sizing in CSS. If you would rather hand the conversion and the testing to someone else, it is the kind of fixed-scope job our website fixes and maintenance service takes on.
Tools mentioned in this post
- PX to REM ConverterConvert px to rem and rem to px at any root font size, with full conversion tables for 16px and 10px roots.
- CSS MinifierStrip comments and whitespace from CSS, safely, and see exactly how much smaller it got.
- Box Shadow GeneratorDial in the perfect CSS shadow with sliders and a live preview.


