CSS // blog
All blog postsHow to Convert PX to REM (and REM to PX) With Simple Math and CSS Examples
px to rem Converter / rem to px ConverterEvery front-end dev has that moment: a designer hands over a layout where every spacing block and font size is measured in pixels (24px, 40px, 80px), and your brain immediately has to translate px to rem without accidentally turning a subheading into a billboard.
Skip the mental division. The px to rem Converter / rem to px Converter flips values between px, rem, and em in this tab. We never see what you paste. Root defaults to 16px, and you can change it when the project uses a different base.
Convert PX to REM and REM to PX in seconds
Type a pixel value like 24 or 80 into the px to rem calculator to see the rem equivalent, or enter a rem number like 1.5 or 1 to convert rem to px on the spot. Paste phrases such as 80 px to rem or 1.5 rem to px if that is how you searched.
Once you dial in type and spacing, jump to the CSS Clamp Generator for fluid typography, or the CSS to Tailwind Converter / Tailwind to CSS Converter if you are working with utility classes. Those tools also run on your computer.
How PX and REM actually work in CSS
If px is the classic ruler in your pocket, rem is a ruler that stretches or shrinks with the font size on the root html element:
| Unit | What it means |
|---|---|
| px | A fixed CSS length. 1px is 1/96 of an inch in CSS reference pixels. Useful for crisp borders and exact alignment. |
| rem | Relative to the root html font size, not the parent. At 16px root, 1rem is 16px, 1.5rem is 24px, and 5rem is 80px. |
| em | Relative to the current element's font size (for font-size, the parent). Nested em values can compound. |
Rem matters when users change the browser default for accessibility, or when you shift a base scale across a design system. Those sizes adapt instead of staying locked in stone.
How to convert PX to REM and REM to PX by hand
A px to rem conversion tool is the fast path when you are moving. The division and multiplication still help when you are reviewing a PR or tweaking a stylesheet in DevTools.
1. The manual math: PX to REM
With a standard root of 16px: rem = px / root font size. Everyday examples:
| Pixels | Rem at 16px root |
|---|---|
| 16px to rem | 1rem (1 rem to px = 16px) |
| 24px to rem | 1.5rem (1.5 rem to px = 24px) |
| 80px to rem | 5rem (80 / 16) |
| 14px to rem | 0.875rem |
2. The reverse math: REM to PX
To convert rem to px, multiply rem by the root font size (16px by default): px = rem x root. For example, 1.5rem to px is 1.5 x 16 = 24px. 0.875rem to px is 0.875 x 16 = 14px.
If a project sets html { font-size: 10px; } so 1.6rem equals 16px, divide or multiply by 10 instead of 16. Always check the root element first.
3. Quick JavaScript helper for PX / REM
Need a tiny helper inside a script, design-token generator, or browser console?
JavaScript
function pxToRem(px, rootPx = 16) {
return Number((px / rootPx).toFixed(4));
}
function remToPx(rem, rootPx = 16) {
return Number((rem * rootPx).toFixed(2));
}
console.log(pxToRem(80)); // 5
console.log(remToPx(1.5)); // 24The px to rem Converter / rem to px Converter copies a Next.js helper in the same shape when you want it in a component.
4. Practical CSS examples (px vs rem)
Mixing px and rem on purpose keeps borders crisp while type and spacing still scale:
CSS
html {
font-size: 16px; /* Default browser base */
}
.hero-title {
font-size: 5rem; /* 80px at 16px root */
line-height: 1.1;
margin-bottom: 1.5rem; /* 24px at 16px root */
}
.card-box {
padding: 1rem; /* 16px */
border: 1px solid #e2e8f0; /* Crisp 1px border */
border-radius: 0.75rem; /* 12px */
}5. Common gotchas that trip developers up
- Confusing rem with em. rem looks at the root
html. em looks at the current element's font size (forfont-size, the parent). Nested em on font-size compounds fast. - Forgetting a custom root. If a stylesheet changes
font-sizeonhtmlat a breakpoint, every rem value shifts with it. Great when you meant it, confusing if you forgot it was there. - Tiny rounding quirks. 18px / 16 is exactly
1.125rem. Other splits may need three or four decimal places. Keep rounding consistent so the CSS stays readable.
Run a quick px to rem check, use a rem to px converter on a spacing token, or do the math yourself with 16px as the baseline. The px to rem Converter / rem to px Converter stays on your computer. We never see the files.
Share