About the PX to REM converter
rem is a CSS unit relative to the root font size, which is 16px by default. Using rem for font sizes and spacing means your layout scales when someone increases the default text size in their browser, which pixel values ignore.
This converter changes px to rem and rem to px using any root font size, shows a table of common sizes, and can convert every pixel value in a whole stylesheet at once.
How to use the PX to REM converter
- Enter a value in Pixels or REM; the other box updates as you type.
- Change Root font size if your site sets a different size on the
htmlelement. - To convert a file, paste your CSS into Your CSS and choose the direction.
- Click Copy CSS to copy the converted stylesheet.
Example
Convert a stylesheet with a 16px root
Input
.card {
padding: 24px 32px;
font-size: 14px;
border: 1px solid #ddd;
border-radius: 12px;
}Output
.card {
padding: 1.5rem 2rem;
font-size: 0.875rem;
border: 1px solid #ddd;
border-radius: 0.75rem;
}1px borders stay 1px, so hairlines don't vanish when rem values round down.
Common errors and how to fix them
rem sizes don't match the design
The root font size isn't 16px. Check html { font-size } in your CSS; with 62.5% (10px), 24px is 2.4rem, not 1.5rem. Set the root size in the converter to match.
Nested text gets smaller and smaller
That's em, which compounds with each nested element. rem is always relative to the root element, so it doesn't compound.
Should media queries use rem?
Media queries in em or rem both use the browser's default size, not your html font size. em is the common choice, and it respects a user's zoom setting.
Good to know
- rem = px ÷ root font size. At the default 16px, 24px is 1.5rem and 1rem is 16px. Results are rounded to at most 4 decimal places.
- Keep 1px values leaves
1pxborders and hairlines alone, since they're meant to stay one device-independent pixel. - Values inside comments, quoted strings and
url(), and names likeicon-16px.svg, are left unchanged.0pxis kept as written. - Media queries can use rem too. Browsers treat rem in media queries as the default font size (usually 16px), regardless of the root font size you set in CSS.
- em is similar but relative to the parent element's font size, so it compounds when elements are nested. rem always refers to the root, which makes it more predictable.
Frequently asked questions
How many pixels is 1rem?
1rem equals the root (html) font size, which is 16px in every major browser by default. If you set html { font-size: 62.5%; }, 1rem becomes 10px; change Root font size to 10 to convert for that setup.
Should I use rem or px?
Use rem for font sizes, and usually for spacing and layout widths, so the design respects people's text size settings. px is fine for borders, shadows and other small details that shouldn't scale.
What's the difference between rem and em?
rem is relative to the root font size, so it's the same everywhere on the page. em is relative to the current element's font size, so a nested element with 1.2em inside another 1.2em ends up 1.44 times larger.