Skip to content
Motion and CSS

PX to REM Converter

Type pixels or rem and get the other at any root size, or paste a whole stylesheet and convert every px value to rem in one go.

Last checked

Convert one value

24px = 1.5rem at a 16px root

1px is 0.0625rem at this root. Change the root only if your CSS sets a different font size on html.

Convert a whole stylesheet

CSS with rem

.card {
  padding: 1.5rem 2rem;
  border: 1px solid #ddd;
  border-radius: 0.75rem;
  font-size: 1.125rem;
  margin-top: -0.5rem;
}

@media (min-width: 768px) {
  .card { padding: 2.5rem; }
}
1 keeps hairline borders; empty converts all

6 values converted, 2 left in px.

PX to REM table at 16px

PixelsREMPixelsREM
1px0.0625rem24px1.5rem
2px0.125rem28px1.75rem
4px0.25rem32px2rem
6px0.375rem36px2.25rem
8px0.5rem40px2.5rem
10px0.625rem48px3rem
12px0.75rem56px3.5rem
13px0.8125rem64px4rem
14px0.875rem72px4.5rem
15px0.9375rem80px5rem
16px1rem96px6rem
18px1.125rem128px8rem
20px1.25rem

How to use it

  1. Type a value in pixels or in rem; the other box updates as you type.
  2. Set the root font size if your CSS changes it on the html element. Leave it at 16px otherwise.
  3. To convert a file, paste the CSS into the stylesheet box and copy the result. Set which small values, properties and @media conditions stay in px.

What it checks and why

A rem is the font size of the root element, the html tag. Browsers set it to 16px unless the page or the visitor changes it, so 24px is 1.5rem and 12px is 0.75rem. The converter divides by the root size you give it and multiplies back for the other direction.

Sizes in rem follow the font size a visitor picks in their browser settings. Sizes in px do not. That is the main reason to write type and spacing in rem: someone who sets a larger default font gets larger text and a layout that grows with it, not text that overflows fixed boxes.

The stylesheet converter finds every length written in px and rewrites it, so a component written in pixels from a design file can move to rem in one paste. It leaves comments, quoted strings and url() paths untouched (so img/16px.png stays a file name), can keep hairlines and chosen properties in px, and by default leaves @media, @container and @supports conditions alone, because rem inside a media query is based on the browser's initial font size, not on what your CSS sets on html.

Specs and sources

Limits

  • The stylesheet converter works on text with a pattern, not a full CSS parser. Check the output of unusual code, such as px inside custom property names.
  • It converts px to rem only. em values depend on the parent element's font size, which a converter cannot know.
  • The result in rem is only as right as the root size you enter. If your CSS sets html to 62.5%, use 10px.

Questions

How many pixels is 1rem?
1rem equals the root font size. Browsers default that to 16px, so 1rem is 16px unless your CSS or the visitor's browser setting changes it.
How do I convert px to rem?
Divide the pixel value by the root font size. At the 16px default, 24px divided by 16 is 1.5rem, and 14px is 0.875rem.
Should I use px or rem for font size?
Use rem for font sizes and most spacing, so text scales with the font size a visitor sets in the browser. Pixels are fine for hairline borders and shadows.
What is the 62.5% trick?
Setting html { font-size: 62.5% } makes 1rem equal 10px at the default, which makes the maths easier. You then have to set body text back to 1.6rem, and third-party components that assume 16px can come out small.
Should media queries use rem or px?
Either works, but rem or em in a media query is based on the browser's initial font size, not on your html rule. That is why the converter leaves media conditions in px unless you ask it not to.
How do I convert rem to px?
Multiply by the root font size. At 16px, 1.5rem is 24px and 0.875rem is 14px. Type in the REM box or switch the table to rem to px.
What is the difference between px, em and rem?
px is a fixed CSS pixel. rem is relative to the root (html) font size, so it means the same everywhere on the page. em is relative to the font size of the element itself (or of its parent, for font-size), so it compounds when elements nest.