Skip to content

PX to REM Converter

1rem is the font size of the html element, and browsers start at 16px. If your CSS has html { font-size: 62.5% }, pick 10 or type 62.5% in the box. That trick has a catch.

24 ÷ 16 = 1.5, so 24px is 1.5rem.

Leave it empty to use the base size.

Fewer decimals can merge values: at 2, 767.98px and 768px both become 48rem.

PX to REM table at 16px

Pixels and the same size in rem. Click a value to copy it.
PX REM

Click any value to copy it. Need rem to px? Read the table from right to left.

Convert a stylesheet

Paste CSS and every px value in your declarations turns into rem, using the base size above. Selectors, strings, url() and comments are left exactly as they are.

Result

The converted CSS shows up here, with every changed value highlighted.

PX to REM Converter (and REM to PX)

What is rem in CSS?

rem means "root em": a size measured against the font size of the html element. Browsers start that at 16px, so 1rem is 16px, 0.5rem is 8px and 1.5rem is 24px.

To go from px to rem, divide by 16 (or whatever your root size is). To go back, multiply. 24 ÷ 16 = 1.5, and 1.5 × 16 = 24. The converter above does this for any base, and it can rewrite a whole stylesheet so you don't have to go through it line by line.

24px equals 1.5rem
24 ÷ 16 = 1.5, at the browser's default 16px
.menu-title {
  font-size: 1.5rem; /* 24px when 1rem is 16px */
}

Today's coffee

That heading is set in 24px type on this page, because nothing here changes the root size. If someone has set their browser to bigger text, it's bigger for them, which is the point.

How to use the converter

Step 1 Check the base size

Leave it at 16 unless your stylesheet changes the font size of html. Look for a line like html { font-size: 62.5% } (that's 10px) or html { font-size: 18px }. The buttons next to the box cover the usual ones, and you can type 62.5% straight into the box: it's read as 62.5% of 16px, so 10px.

Step 2 Type a number in any box

Put 24 in Pixels and REM shows 1.5. Put 0.875 in REM and Pixels shows 14. The em, pt and percent boxes follow along too. Arrow up and down nudge the number, and each box has a copy button that copies the value with its unit.

Step 3 Grab values from the table

The table lists the sizes people reach for most, from 1px to 96px, at your base size. Click a value to copy it, copy the whole rem column, or copy it all as CSS variables like --size-24: 1.5rem; for a :root block.

Step 4 Or convert a whole stylesheet

Paste your CSS into Convert a stylesheet. Every px value in a declaration changes and the result highlights each one. The summary counts what changed and what was left alone on purpose. When it looks right, press Copy result.

Why rem is better for people who need bigger text

Every browser has a default text size setting. In Chrome it's under Settings, Appearance, Font size, and it goes from Very small to Very large. People with low vision often turn it up. Font sizes in rem grow with that setting. Font sizes in px ignore it.

/* Stays 24px, whatever the reader picked */
.price-px  { font-size: 24px; }

/* 1.5 × the reader's text size */
.price-rem { font-size: 1.5rem; }

Latte $4.50 24px

Latte $4.50 1.5rem = 24px

The buttons pretend to change that setting (the real one lives in your browser, a web page can't touch it). At Large, the rem price is 30px and the px price is still 24px. Page zoom with Ctrl and + is different: it scales px and rem alike, which is why testing with zoom alone hides the problem. Zoom is enough for WCAG's "resize text to 200%" rule, but the people who change the text size setting instead only get bigger text from rem and em.

rem vs em: why em adds up

em is measured against the parent's font size instead of the root. That's useful, but it compounds when you nest elements. Here are the same lists, one with em and one with rem:

.em li  { font-size: 1.2em; }
.rem li { font-size: 1.2rem; }
  • Coffee
    • Espresso
      • Doppio
  • Coffee
    • Espresso
      • Doppio

With em, each level is 1.2 times the one above it: 19.2px, then 23.04px, then 27.65px. With rem, every level is 19.2px. That's why rem is the safer default for font sizes, and em is better for things that should scale with the text right next to them, like a button's padding or an icon inside a heading. The font size tutorial has more examples of px, rem, em and %.

When px is still the right choice

Not everything should grow with the text. A 1px border is meant to be a thin line, and turning it into 0.0625rem only makes it look odd at bigger text sizes. Shadows and outlines are similar. A sensible card mixes both:

.card {
  padding: 1.5rem;
  border: 1px solid #e5e7eb;
  border-radius: 0.75rem;
  box-shadow: 0 2px 4px rgb(0 0 0 / 10%);
}

The spacing and the corner radius grow with the text, the border and shadow stay crisp. That's why Convert a stylesheet has "Leave 1px and smaller alone" switched on, and why you can limit it to font sizes and spacing with "Only some properties".

The 62.5% trick, and its catch

Some stylesheets set the root to 62.5% so that 1rem is 10px and the math is easy:

html { font-size: 62.5%; }  /* 1rem = 10px */
body { font-size: 1.6rem; }  /* back to 16px */
h1   { font-size: 3.2rem; }  /* 32px */

It still respects the reader's setting (62.5% of a 20px default is 12.5px), so it's not bad for accessibility in itself. The catch is everything around it:

With a converter at hand, easy math isn't much of a reason any more. If your project already uses the trick, set the base to 10 at the top of this page and everything lines up.

Media queries in em or rem

/* Two columns once there's room for them */
@media (min-width: 48em) {
  .menu { display: grid; grid-template-columns: 1fr 1fr; }
}

In a media query, em and rem are measured against the browser's starting font size, not against html { font-size }. So 48em is 768px for most people. For someone with a 20px default it's 960px, and the menu stays in one column a bit longer, which keeps their bigger text from getting squeezed. Both units behave the same here, so pick one and stick to it.

Convert a stylesheet leaves media and container queries alone unless you untick "Leave media and container queries alone". When it does convert them, media queries always use 16px, even if your base is 10, because that's what the browser will do. Container queries are different: rem there means the html font size, so they use your base.

Converting a whole stylesheet

Here's a small button rule run through the converter with the default options:

Before

.signup-btn {
  padding: 12px 24px;
  font-size: 18px;
  border: 1px solid #3f6212;
  background: url("icons/arrow-16px.svg") no-repeat right 12px center;
}
@media (min-width: 640px) {
  .signup-btn { font-size: 20px; }
}

After

.signup-btn {
  padding: 0.75rem 1.5rem;
  font-size: 1.125rem;
  border: 1px solid #3f6212;
  background: url("icons/arrow-16px.svg") no-repeat right 0.75rem center;
}
@media (min-width: 640px) {
  .signup-btn { font-size: 1.25rem; }
}

The padding, font size and background position changed. The 1px border and the media query stayed in px, and so did arrow-16px.svg, because it's a file name. The converter reads CSS the way a browser does, so it never touches selectors (.icon-24px is a class name, not a size), strings, url() or comments. A 0px becomes plain 0, except inside calc() and CSS variables, where a bare 0 would break the math. Run the result through the CSS Formatter if you want it tidied, or the CSS Minifier before you ship it.

Anything inside @property stays in px, because its initial-value can't use rem (browsers throw the whole rule away if it does). And SCSS $gap: 16px and Less @gap: 16px variables are converted like any other value, but sizes worked out by Sass or Less functions are only as right as the numbers you feed them.

Decimals matter more than they look. The default is 5, which keeps every half pixel exact at 16px (13.5px is 0.84375rem). At 2 decimals, 767.98px and 768px both become 48rem, so two breakpoints meant to be apart land on the same width.

"Keep a px line as a fallback" writes the old px declaration right above each new one. Every browser in use today understands rem, so you'll rarely need it. HTML email is the exception: Outlook on Windows doesn't know rem at all.

rem in Tailwind CSS

Tailwind's spacing and text sizes are already in rem: p-4 is 1rem (16px), gap-6 is 1.5rem (24px) and text-sm is 0.875rem (14px).

REM to PX table

The table in the tool goes from px to rem. Here's the other direction, for the default 16px root and for a 10px root (the 62.5% trick):

REM PX at 16px PX at 10px
0.125rem 2px 1.25px
0.25rem 4px 2.5px
0.5rem 8px 5px
0.625rem 10px 6.25px
0.75rem 12px 7.5px
0.875rem 14px 8.75px
1rem 16px 10px
1.125rem 18px 11.25px
1.25rem 20px 12.5px
1.5rem 24px 15px
1.75rem 28px 17.5px
2rem 32px 20px
2.25rem 36px 22.5px
2.5rem 40px 25px
3rem 48px 30px
3.75rem 60px 37.5px
4rem 64px 40px
5rem 80px 50px
6rem 96px 60px

What this converter can't do

More CSS tools

Frequently asked questions

How do I convert px to rem?

Divide the pixel value by the root font size, which is 16px unless your CSS changes it. 24px ÷ 16 = 1.5, so 24px is 1.5rem. 14px is 0.875rem and 32px is 2rem. Type any px value into the converter at the top of this page and it does the math for you, with whatever base size you set.

How do I convert rem to px?

Multiply by the root font size. With the usual 16px, 1.5rem × 16 = 24px and 0.75rem × 16 = 12px. If your stylesheet sets html { font-size: 62.5% }, the root is 10px, so 2.4rem is 24px. Type the rem value into the REM box and the px box updates.

How many pixels is 1rem?

1rem is the font size of the html element. In every major browser that starts at 16px, so 1rem is 16px unless the site's CSS changes it. It can also change when a visitor picks a bigger default font size in their browser settings: with a 20px default, 1rem is 20px. That's the whole point of rem.

What is the difference between rem and em?

rem is always measured against the html element, so 1.5rem is the same size everywhere on the page. em is measured against the parent's font size, so it stacks up when you nest things: a list item set to 1.2em inside another 1.2em list item ends up at 1.44 times the size. Use em when something should grow with the text right around it, like the padding of a button, and rem for everything else.

Should I use px or rem for font sizes?

rem, in most cases. Some people set a bigger default text size in their browser because small text is hard for them to read. Font sizes in rem follow that setting and font sizes in px don't. Page zoom (Ctrl and +) scales both, so you won't notice the difference by zooming. For borders, hairlines and small shadows, px is fine.

What does html { font-size: 62.5% } do?

It makes 1rem equal to 10px (62.5% of 16px), so the math is easy: 2.4rem is 24px. It works, but it has costs. Any text without its own font size drops to 10px, so you have to set body back to 1.6rem. Widgets and libraries that use rem shrink too. And media queries ignore it: 48rem in a media query is still 768px, not 480px. If you use it, set the base on this page to 10.

Does rem in a media query use the html font size?

No. In a media query, rem and em are measured against the browser's starting font size (16px unless the visitor changed it), not against html { font-size }. So @media (min-width: 48rem) means 768px even on a site that uses the 62.5% trick. When you convert a stylesheet here and untick Leave media and container queries alone, media queries are converted with 16px for that reason. Container queries are the exception: there rem does follow the html font size, so they use your base.

Can I convert a whole CSS file from px to rem?

Yes. Paste it into Convert a stylesheet. Every px value inside declarations is changed, and the summary tells you how many. Selectors, strings, url() paths and comments stay as they were, so a class like .icon-24px or an image called logo-48px.png is safe. You can leave 1px borders and media queries alone, convert only some properties (font sizes and spacing, say), or keep a px line before each rem line. It works the other way too, rem to px.

Is my CSS sent anywhere?

No. All the converting happens in your browser and nothing you paste is uploaded. The CSS you paste is not saved either. Your options (base size, decimals, the stylesheet settings) and the last value you typed are kept in this browser so they are still there next time.