StringMash.com

px to rem converter

One value, a list, or a whole block of CSS, at any root font size.

Conversion
2 characters
Updates as you type
Paste CSS to convert every px value in it

Show the steps
  1. rem = px ÷ root font size. The root font size here is 16px.
  2. 24px ÷ 16 = 1.5rem
  3. So 24px is 1.5rem.

Using the converter

Type a size in pixels, with or without px, and the rem value appears on the right. 24 gives 1.5rem. A list works too, and 8, 12, 16 comes back as 0.5rem, 0.75rem, 1rem with the commas where you left them.

Paste a whole rule or stylesheet and every px value in it is rewritten. Numbers without a unit stay put, so a line-height of 1.5 or a z-index of 10 doesn't change, and 0px becomes plain 0. Anything inside comments, quoted strings or url() is left alone, along with @media and @container conditions.

Set Leave values under to 2 to keep 1px borders and hairlines in pixels. Press swap, or open the rem to px converter, to go the other way. Nothing you paste leaves your device.

Common sizes in rem

At a root font size of 16px, with 4 decimal places at most.
pxrem
8px0.5rem
10px0.625rem
12px0.75rem
14px0.875rem
16px1rem
18px1.125rem
20px1.25rem
24px1.5rem
32px2rem
40px2.5rem
48px3rem
64px4rem

How to convert px to rem

Divide by the root font size. The root is the <html> element, and unless your CSS sets its font-size, browsers start it at 16px. So 24px ÷ 16 = 1.5rem, and 14px ÷ 16 = 0.875rem.

If your stylesheet sets a different root, put that in the Root font size box and the converter and the table above both follow it. At a 10px root, 24px is 2.4rem.

rem, em and px

A px is a fixed CSS length, defined as 1/96 of an inch. On a high-density screen one CSS pixel covers several device pixels, but it's still the same size to your eye.

rem means root em. One rem is the font size of the <html> element, the same everywhere on the page.

em is the font size of the element you're styling. Inside a font-size declaration it's the parent's size, so ems compound. A list at 0.8em inside another list at 0.8em ends up at 0.64 of the outer text. rem never does that, so it's the easier unit for sizes you want to stay put. em is handy when something should scale with its own text, like the padding on a button.

Why rem respects the reader

Browsers have two ways to make text bigger. Zoom enlarges everything, pixels included. The font size setting changes the default text size, and the default is what 1rem is measured against. Text set in rem grows when a reader picks a larger default; text set in px ignores it.

WCAG 2.2 success criterion 1.4.4, Resize Text, asks that text can be resized to 200% without losing content or function. That's level AA. Zoom alone can meet it, but rem-based sizes honour the reader's chosen default as well, and some people with low vision rely on that setting.

The 62.5% trick

Some stylesheets set html { font-size: 62.5%; }. 62.5% of 16px is 10px, so 1rem becomes 10px and the sums get easier, with 24px becoming 2.4rem. Written as a percentage it still follows the reader's default. A reader who picks 20px gets a 12.5px root and everything scales with it.

The cost shows up elsewhere. Body text then needs font-size: 1.6rem to get back to 16px. Anything written for a 16px root shrinks to 62.5%, including third-party widgets and Tailwind, whose p-4 turns from 16px into 10px. Never set the root in px, like font-size: 10px, because that replaces the reader's choice outright.

Questions

What is 16px in rem?

1rem, when the root font size is the browser default of 16px.

How many px is 1rem?

Whatever the root font size is. That's 16px in most browsers unless the reader has changed their default or your CSS sets a size on `html`.

What spacing does Tailwind use?

Tailwind CSS v4 sets `--spacing: 0.25rem` and builds its spacing utilities as multiples of it, so `p-4` is `calc(var(--spacing) * 4)`, which is 1rem or 16px at the default root. To find the Tailwind number for a size, convert it to rem and multiply by 4. 24px is 1.5rem, so `p-6`.

Should borders be in rem?

Usually not. A hairline is meant to stay one pixel whatever the text size, and as 0.0625rem it grows and shrinks with the root. Set Leave values under to 2 and hairlines stay in pixels.

Why are media queries left in px?

rem in a media query is measured against the browser's initial font size, not the size your stylesheet gives `html`. If your root isn't 16px, a converted breakpoint would land in the wrong place, so they're left for you to decide.

Can I convert px to em with this?

Yes, if you put the parent element's font size in the Root font size box and read the result as em. The maths is the same, px divided by the font size in charge.

Sources

Added and reviewed . What's new