Free tool

PX to REM converter

To convert px to rem, divide the pixels by the root font size: at the browser default of 16px, 24px = 1.5rem and 14px = 0.875rem. Set your own root size below, convert one value either way, or paste a whole stylesheet to convert every px value at once.

Free · no sign-up · runs in your browser, nothing is uploaded

px → rem
px
rem

1rem = 16px. The root is the font-size of the html element; browsers default to 16px.

Result

24px = 1.5rem

CSS 1.5rem /* 24px */

Tailwind class

v4: p-6

v3: p-6

font-size: text-2xl

Also

18pt

1.5em

Conversion table at 16px root
1px0.0625rem
2px0.125rem
4px0.25rem
6px0.375rem
8px0.5rem
10px0.625rem
12px0.75rem
13px0.8125rem
14px0.875rem
15px0.9375rem
16px1rem
18px1.125rem
20px1.25rem
22px1.375rem
24px1.5rem
28px1.75rem
30px1.875rem
32px2rem
36px2.25rem
40px2.5rem
44px2.75rem
48px3rem
56px3.5rem
60px3.75rem
64px4rem
72px4.5rem
80px5rem
96px6rem
112px7rem
128px8rem

Convert a whole stylesheet

CSS with px
CSS with rem

Paste CSS, SCSS or a style attribute. Every px value is converted at 16px; comments, strings and url() stay as they are.

PX to REM conversion table (16px root)

The most used sizes at the browser default. For another root size, change it in the tool above and the table there updates.

PixelsREMPixelsREM
1px0.0625rem28px1.75rem
2px0.125rem30px1.875rem
4px0.25rem32px2rem
6px0.375rem36px2.25rem
8px0.5rem40px2.5rem
10px0.625rem44px2.75rem
12px0.75rem48px3rem
13px0.8125rem56px3.5rem
14px0.875rem60px3.75rem
15px0.9375rem64px4rem
16px1rem72px4.5rem
18px1.125rem80px5rem
20px1.25rem96px6rem
22px1.375rem112px7rem
24px1.5rem128px8rem

The formula, and what the root font size is

rem = px ÷ root font size

24px ÷ 16 = 1.5rem
14px ÷ 16 = 0.875rem
24px ÷ 10 = 2.4rem   (html { font-size: 62.5%; })

1rem is the computed font-size of the root html element. Browsers start it at 16px, and a user can change that default in their browser settings. If your CSS sets html { font-size: 62.5%; }, the root becomes 10px (62.5% of 16px) and the math gets easier: 24px is 2.4rem. Setting the root in px (font-size: 10px) also works, but it overrides the user's chosen text size, which is the main reason to use rem in the first place.

Not sure what your project uses? Run getComputedStyle(document.documentElement).fontSize in the browser console on your site.

Convert px to rem in Sass, JavaScript and PostCSS

Sass (use math.div; the / division operator is deprecated):

@use 'sass:math';

@function rem($px, $root: 16px) {
  @return math.div($px, $root) * 1rem;
}

.card { padding: rem(24px); }   // 1.5rem

JavaScript, using the root size the page really has:

const root = parseFloat(getComputedStyle(document.documentElement).fontSize); // 16
const pxToRem = px => `${px / root}rem`;
pxToRem(24); // "1.5rem"

PostCSS: the postcss-pxtorem plugin rewrites px to rem at build time, so you can keep writing px. Its propList and minPixelValue options do what the "keep 1px borders" switch does in the tool.

Tailwind CSS: one spacing step is 0.25rem, so 24px is 1.5rem is p-6. The tool shows the class for each value. Tailwind v4 accepts any multiple of 0.25 (like p-13), while v3 has a fixed scale and needs an arbitrary value such as p-[3.25rem] between its steps. The REM to PX converter has the full Tailwind spacing table.

When to use rem, and when to keep px

PropertyUnitWhy
font-sizeremFollows the reader’s default text size
padding, margin, gaprem (or em)Spacing grows with the text, so layouts don’t get cramped
max-width of text columnsrem or chKeeps line length readable at any text size
border, outline, hairlinespxA 1px line should stay thin
box-shadow offsetspxUsually decorative and small
media query breakpointsem or remBreakpoints move with the user’s default text size
line-heightunitless (1.5)Scales with each element’s own font-size

WCAG 2.2 asks that text can be resized to 200% without losing content (success criterion 1.4.4). Browser zoom does that for px too, but people who raise only the default font size in their settings get bigger text only where the CSS uses rem or em.

Gotchas when converting

  • Media queries ignore your root. @media (min-width: 48rem) is always 48 times the browser default (768px at 16px), even with html { font-size: 62.5% }. Convert breakpoints with 16, not 10.
  • em compounds, rem does not. Swapping px for em in nested components makes sizes multiply. rem is the safer one-to-one replacement.
  • Long decimals are fine. 13px is 0.8125rem; browsers handle the decimals, and rounding to 0.81rem changes the result by a fraction of a pixel.
  • Tailwind's rem values assume 16px. If you set the root to 10px, p-4 becomes 10px instead of 16px. Change the root and the whole scale moves.
  • 1px = 0.0625rem. A border in rem grows with the reader's default text size: with a 20px default, 0.0625rem is 1.25px. Hairlines are meant to stay thin, so keep them in px (the bulk converter does that by default).

Shrinking CSS after converting? The CSS minifier removes whitespace and comments. For sizing images and video, try the aspect ratio calculator, and browse Tailwind CSS tools on DevHunt.

FAQ

How do I convert px to rem?+

Divide the pixel value by the root font size. With the browser default of 16px, 24px ÷ 16 = 1.5rem and 14px ÷ 16 = 0.875rem. If your html element sets a different font-size, divide by that number instead.

What is 1px in rem?+

At a 16px root, 1px is 0.0625rem (1 ÷ 16). At a 10px root it is 0.1rem. Most teams keep 1px borders and hairlines in px, because they should stay one pixel thin whatever the text size.

What is 20px in rem?+

1.25rem at the default 16px root (20 ÷ 16). At a 10px root (html { font-size: 62.5% }) it is 2rem.

What is 1rem in px?+

1rem equals the font-size of the root html element. That is 16px in every major browser unless the page or the user changes it, so 1rem is usually 16px, but not always.

Should I use px or rem?+

Use rem for font sizes, and usually for spacing and layout widths, so the page scales when someone raises the default text size in their browser settings. Use px for borders, outlines and shadows that should not grow. Browser zoom scales both px and rem, so zoom alone is not a reason to pick one.

What is the difference between rem and em?+

rem is relative to the root html element, so 1.5rem is the same size everywhere on the page. em is relative to the font-size of the element itself (or its parent, when used in font-size), so nested em values compound: 1.2em inside 1.2em is 1.44 times the outer size.

Does rem in a media query use my root font size?+

No. In a media query condition, rem and em are based on the browser default font size, not on the font-size you set on html. @media (min-width: 48rem) is 768px with a 16px default even if your root is 10px. The bulk converter above uses 16px inside @media conditions for that reason.

Sources: CSS Values and Units 4: font-relative lengths · CSS Values and Units 4: absolute lengths · Media Queries 4: units · MDN: CSS length units · MDN: font-size · WCAG 2.2: 1.4.4 Resize text · Sass: math.div · Tailwind CSS: padding and the spacing scale · postcss-pxtorem. Checked 2026-10-30.