PX to REM Converter

Type a length to see it in px, rem, em, pt and %, or paste CSS to convert all px values to rem at once while 1px borders, url() and comments stay untouched.

Loading tool…

About the PX to REM Converter

A rem is the font size of the root element (<html>), which is 16px in every browser unless the user or the page changes it. The conversion is a division: rem = px / root font size, so 24px is 1.5rem at the default size. An em uses the font size of the element itself (of the parent, for the font-size property), which is why nested em values compound and rem values do not. A percentage on font-size works like em × 100. A CSS pt is fixed at 1/72 inch and CSS defines 96px to the inch, so 1pt is always 1.333px and 12pt is 16px.

Sizing in rem is an accessibility matter: a reader who sets the browser's default font size to 20px gets larger text only where the stylesheet uses relative units. WCAG success criterion 1.4.4 asks that text can be resized up to 200% without loss of content. Browser zoom scales px too, but the font size preference does not. For this reason, do not set html { font-size: 16px }; leave the root alone or use a percentage such as 62.5%, which makes 1rem equal to 10px while still following the user's setting.

The bulk converter reads the stylesheet as CSS rather than as plain text. It only rewrites values of declarations, so class names such as .w-16px, comments, quoted strings and url() contents are never changed. Values inside calc(), shorthands like margin: 4px 8px, negative numbers and custom properties are converted. Hairlines are usually better left in px, since a 1px border should not grow with the font size: the threshold keeps every value at or below the size you choose. Note that rem inside a media query always refers to the browser's initial font size, not to the font size set on html.

How to use it

  1. Set the root font size if your project does not use the default 16px.
  2. Type a value and choose its unit to see it in every other unit.
  3. Paste a stylesheet into the CSS panel to convert all of its px values to rem, or switch to rem → px.
  4. Adjust the decimals, the px threshold and the properties to skip, such as border*.
  5. Copy or download the converted CSS.

Frequently asked questions

How many rem is 16px?
1rem at the default root font size of 16px. Divide the px value by the root font size: 8px is 0.5rem, 12px is 0.75rem, 20px is 1.25rem, 24px is 1.5rem and 32px is 2rem.
What is the difference between rem and em?
rem is always relative to the font size of the root element, so 1rem is the same length everywhere on the page. em is relative to the font size of the element it is used on, so it changes with nesting. Use rem for consistent spacing and type scales, em for things that should scale with their own text, such as the padding of a button.
Should borders and media queries be converted to rem?
Borders of 1px usually stay in px so that they remain hairlines; the threshold option keeps them. Media queries in rem or em are a good idea, because the layout then adapts to the user's font size, but remember that they use the browser's initial font size and ignore the font size set on the html element.
Why is 0px not converted?
Zero is the same length in every unit, so the value is left exactly as written. This also avoids turning calc(100% - 0px) into an invalid expression with a unitless zero.

Related tools