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
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
Convert a whole stylesheet
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.
| Pixels | REM | Pixels | REM |
|---|---|---|---|
| 1px | 0.0625rem | 28px | 1.75rem |
| 2px | 0.125rem | 30px | 1.875rem |
| 4px | 0.25rem | 32px | 2rem |
| 6px | 0.375rem | 36px | 2.25rem |
| 8px | 0.5rem | 40px | 2.5rem |
| 10px | 0.625rem | 44px | 2.75rem |
| 12px | 0.75rem | 48px | 3rem |
| 13px | 0.8125rem | 56px | 3.5rem |
| 14px | 0.875rem | 60px | 3.75rem |
| 15px | 0.9375rem | 64px | 4rem |
| 16px | 1rem | 72px | 4.5rem |
| 18px | 1.125rem | 80px | 5rem |
| 20px | 1.25rem | 96px | 6rem |
| 22px | 1.375rem | 112px | 7rem |
| 24px | 1.5rem | 128px | 8rem |
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.5remJavaScript, 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
| Property | Unit | Why |
|---|---|---|
| font-size | rem | Follows the reader’s default text size |
| padding, margin, gap | rem (or em) | Spacing grows with the text, so layouts don’t get cramped |
| max-width of text columns | rem or ch | Keeps line length readable at any text size |
| border, outline, hairlines | px | A 1px line should stay thin |
| box-shadow offsets | px | Usually decorative and small |
| media query breakpoints | em or rem | Breakpoints move with the user’s default text size |
| line-height | unitless (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 withhtml { 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-4becomes 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.
More free developer tools
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.