html { font-size: ... }.
Paste a CSS block — every px (or rem) value will be converted using your root font size above.
| Pixels | Rem |
|---|
Quick answer
To convert px to rem, divide the pixel value by the root font size — rem = px ÷ 16 at the browser default. rem is preferred over px for font sizes and spacing because it scales with the user's browser font setting, which matters for accessibility. This tool does single values and whole CSS blocks in your browser, with a configurable root size — nothing is uploaded.
How the Conversion Works
The formula for both directions:
rem = px ÷ root_font_size
px = rem × root_font_size
The browser default root font size is 16px, so 1rem = 16px. If your CSS sets html { font-size: 62.5%; }, the root becomes 10px and 1rem = 10px — change the root font size input above to match your project.
When to still use px
- Borders — A
1pxborder maps to 1 device pixel; a0.0625remborder can render fuzzy on scaled screens. - Box shadows — Shadow blur and offset feel more predictable in absolute units.
- Media query breakpoints —
pxbreakpoints are common and acceptable;emis recommended for zoom-awareness but not universal. - Fixed-size icons — When an icon must match a pixel grid (favicon, app icon),
pxis the right unit.
The 62.5% pattern
Setting html { font-size: 62.5%; } makes 1rem = 10px, so 1.6rem = 16px and 2.4rem = 24px — simpler mental math. If you use this pattern, set the body to font-size: 1.6rem so default text is still ~16px. Enter 10 in the root font size field above to use this pattern.
Worked example
Paste a CSS rule into the bulk converter (root font size 16) and every px value is divided by 16:
Input CSS
.card {
padding: 24px;
margin-bottom: 16px;
font-size: 14px;
border: 1px solid #ccc;
}
Output CSS (px → rem)
.card {
padding: 1.5rem;
margin-bottom: 1rem;
font-size: 0.875rem;
border: 0.0625rem solid #ccc;
}
What happened
- Each value was divided by 16:
24 ÷ 16 = 1.5,16 ÷ 16 = 1,14 ÷ 16 = 0.875. - The selector, the colour
#ccc, and all non-pxtext were left untouched — only numbers followed bypxchanged. - Note the
1pxborder became0.0625rem. That's mathematically correct but usually not what you want — hairline borders are normally best left inpx(see gotchas).
Edge cases & gotchas
- Bulk conversion is blind to intent. It converts every
px, including 1px borders, hairlines, and shadow offsets you probably want to keep pixel-perfect. Review the output and revert those. - Set the root size to match your project. Conversion uses the root font size field. If your CSS sets
html { font-size: 62.5% }(10px), leave the field at 16 and every value is wrong by 1.6× — set it to 10 first. - rem is the root; em is the parent.
emcompounds through nesting, so a1.2eminside another1.2emis 1.44× the root.remalways refers to the single root size. - Fractional rem is normal but noisy.
15px ÷ 16 = 0.9375rem. Browsers handle the decimals fine; teams that dislike them adopt the 62.5% pattern for round numbers. - Prefer
emfor media queries. For zoom-aware breakpoints,emis the most consistent unit across browsers;pxbreakpoints are common and fine, but ignore the user's font-size zoom.
Frequently Asked Questions
What is the formula for converting px to rem?
rem = px ÷ root_font_size. The browser default root font size is 16px, so 24px ÷ 16 = 1.5rem. If you change the root font size with html { font-size: ... }, divide by that value instead.
Why use rem instead of px?
rem scales with the user's browser font size setting, which is critical for accessibility. A user who increases their browser font size to 20px (because they have low vision) will see your 1rem spacing grow proportionally; 16px spacing stays at 16px regardless.
What's the difference between rem and em?
em is relative to the parent element's font size. rem is relative to the root element's (html) font size. rem is more predictable because it has a single source of truth, while em compounds when nested.
Is my CSS sent to a server?
No. All conversion happens in your browser. Your CSS never leaves your device.
Does this work with Sass or SCSS?
Yes. Paste a Sass or SCSS block into the bulk converter — it operates on raw text and only touches numeric values immediately followed by px or rem. Variables, mixins, selectors, and comments are left untouched. Note that it converts every matching value, so a 1px border becomes 0.0625rem too; review the output if you want to keep some values in px.