# 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.

- Page: https://codethatmoves.com/tools/motion/px-to-rem/
- Site: Code That Moves
- Category: Motion and CSS
- Free, runs in the browser, nothing is uploaded
- Last checked: 2026-11-03

## What it does

- Two-way conversion between px and rem at any root font size
- Presets for the 16px browser default and the 62.5% (10px) root trick
- Converts every px value in pasted CSS to rem; comments, strings and url() left alone
- Keep values up to a size you choose in px, pick the decimals, and leave properties such as border* or box-shadow in px
- Leaves @media, @container and @supports conditions in px by default
- A px to rem and rem to px table for common sizes, and a share link

## 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

- [W3C: CSS Values and Units, font-relative lengths](https://www.w3.org/TR/css-values-4/#font-relative-lengths)
- [MDN: CSS length units](https://developer.mozilla.org/en-US/docs/Web/CSS/length)
- [W3C: Media Queries Level 4, units in media queries](https://www.w3.org/TR/mediaqueries-4/#units)
- [WCAG 2.2: Understanding 1.4.4 Resize Text](https://www.w3.org/WAI/WCAG22/Understanding/resize-text.html)

## 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.
