PX to REM Converter

Convert px to rem, rem to px and px to em at any root font size, or paste a whole stylesheet. Tailwind classes and clamp() included. Runs in your browser; nothing is uploaded.

px, rem and em, both ways

Type in any box.

html font size; 16 is the browser default, 10 for 62.5%

the parent's font size (for font-size) or the element's own

16px = 1rem = 1em

rem = 16 ÷ 16 = 1 · em = 16 ÷ 16 = 1 · also 12pt and 100% of the em base

Tailwind CSS (tap a class to copy it)

spacing step 4 in v3 and v4

Common sizes

Convert a whole stylesheet

Skip properties

Uses the root size set above (16px). Comments, strings, url(), selectors and @container queries are never changed; write PX to keep a value in pixels.

The converted stylesheet appears here as you type. No CSS to hand? Press Example.

PX to REM conversion table (1–100px)

At a 16px root font size. Change the root size in the converter and the table follows.

px to rem, 1 to 25px
pxrem
1px0.0625rem
2px0.125rem
3px0.1875rem
4px0.25rem
5px0.3125rem
6px0.375rem
7px0.4375rem
8px0.5rem
9px0.5625rem
10px0.625rem
11px0.6875rem
12px0.75rem
13px0.8125rem
14px0.875rem
15px0.9375rem
16px1rem
17px1.0625rem
18px1.125rem
19px1.1875rem
20px1.25rem
21px1.3125rem
22px1.375rem
23px1.4375rem
24px1.5rem
25px1.5625rem
px to rem, 26 to 50px
pxrem
26px1.625rem
27px1.6875rem
28px1.75rem
29px1.8125rem
30px1.875rem
31px1.9375rem
32px2rem
33px2.0625rem
34px2.125rem
35px2.1875rem
36px2.25rem
37px2.3125rem
38px2.375rem
39px2.4375rem
40px2.5rem
41px2.5625rem
42px2.625rem
43px2.6875rem
44px2.75rem
45px2.8125rem
46px2.875rem
47px2.9375rem
48px3rem
49px3.0625rem
50px3.125rem
px to rem, 51 to 75px
pxrem
51px3.1875rem
52px3.25rem
53px3.3125rem
54px3.375rem
55px3.4375rem
56px3.5rem
57px3.5625rem
58px3.625rem
59px3.6875rem
60px3.75rem
61px3.8125rem
62px3.875rem
63px3.9375rem
64px4rem
65px4.0625rem
66px4.125rem
67px4.1875rem
68px4.25rem
69px4.3125rem
70px4.375rem
71px4.4375rem
72px4.5rem
73px4.5625rem
74px4.625rem
75px4.6875rem
px to rem, 76 to 100px
pxrem
76px4.75rem
77px4.8125rem
78px4.875rem
79px4.9375rem
80px5rem
81px5.0625rem
82px5.125rem
83px5.1875rem
84px5.25rem
85px5.3125rem
86px5.375rem
87px5.4375rem
88px5.5rem
89px5.5625rem
90px5.625rem
91px5.6875rem
92px5.75rem
93px5.8125rem
94px5.875rem
95px5.9375rem
96px6rem
97px6.0625rem
98px6.125rem
99px6.1875rem
100px6.25rem

Fluid size calculator: clamp()

Sizes are written in rem using the root size above (16px), so the result still grows when someone enlarges their default font size.

font-size at 800px: 20px (1.25rem)

Fluid heading

✓ The largest size is 1.5× the smallest, within the 2.5× limit, so zooming can still double the text (WCAG 1.4.4).

clamp() code

CSS declaration

font-size: clamp(1rem, 0.8333rem + 0.8333vw, 1.5rem);

Why rem? Change the default font size

Browsers let people choose a bigger default text size. Text sized in rem follows that choice; text sized in px does not. Drag to simulate the setting:

font-size: 18px

Set in pixels, this line ignores the setting.

Rendered at 18px

font-size: 1.125rem

Set in rem, this line grows with it.

Rendered at 18px

Simulated on this page. The real setting: Chrome, Settings › Appearance › Font size; Edge, Settings › Appearance › Fonts; Firefox, Settings › General › Fonts. Page zoom (Ctrl or ⌘ and +) enlarges both lines; only this setting tells them apart.

Why convert px to rem?

Pixels are how designs are handed over: a mock-up says 24px, a style guide says 14px. rem is how the browser should receive them, because a size in rem follows the root font size, and with it the reader's own choice of text size in their browser settings. Converting is simple division, but doing it by hand for every value in a stylesheet is slow and easy to get wrong, especially around borders, media queries and calc(). This converter does single values both ways, whole stylesheets in one paste, Tailwind classes and fluid clamp() values, all in your browser.

How to convert px to rem

  1. Set the root font size: leave 16 unless your CSS changes the html font size (62.5% means 10).
  2. Type a value in Pixels, REM or EM; the other two update instantly. Tap a Tailwind class to copy it.
  3. To convert a file, paste it into Convert a whole stylesheet, pick how to treat hairlines and media queries, and check the Changes view.
  4. Press Copy or Download. Your settings live in the page link, so you can bookmark or share them.

How to convert px to rem, with examples

A rem is the root element's font size. Browsers use 16px for it unless the page or the reader changes it, so the conversion is one division:

rem = px ÷ root font size      px = rem × root font size
  • 24px to rem: 24 ÷ 16 = 1.5rem.
  • 14px to rem: 14 ÷ 16 = 0.875rem.
  • 1.25rem to px: 1.25 × 16 = 20px.
  • With the 62.5% root (1rem = 10px): 24px is 24 ÷ 10 = 2.4rem.
  • 24px to em inside a 20px parent: 24 ÷ 20 = 1.2em.

Results are rounded to four decimal places, which is far finer than a screen can show: 0.0001rem is less than a fiftieth of a pixel.

px vs rem vs em: what each unit is relative to

UnitRelative toGrows with the font size setting?Good for
pxNothing (a CSS pixel, 1/96 inch)No (zoom only)Hairline borders, shadows, small fixed details
remThe html element's font sizeYesFont sizes, spacing, layout widths: one consistent scale
emThe element's own font size (the parent's, for font-size)YesPadding that should scale with its own text, icons beside text
%The parent (font size, or width for widths)Yes, for font-sizeFluid widths; font sizes like em

em compounds: a 1.2em list nested inside another 1.2em list is 1.44 times the base size, and a third level is 1.728 times. rem never compounds, which is why most design systems size everything in rem and keep em for padding inside buttons and badges.

How the stylesheet converter works

Paste a stylesheet and every px value inside a declaration is divided by your root size. Everything that isn't a length in a declaration is left exactly as written. This is the Example stylesheet, converted with the default settings when this page was built:

Before

/* Card, 16px root */
.card-320px {
  max-width: 320px;
  padding: 24px 20px;
  margin: 0 auto 32px;
  border: 1px solid #d0d7de;
  border-radius: 12px;
  font: 15px/24px "Inter", sans-serif;
  background: url("img/bg-64px.png") no-repeat;
}
.card-320px h2 {
  font-size: 22px;
  letter-spacing: -0.5px;
  width: calc(100% - 0px);
  outline-offset: 2PX;
}
@media (min-width: 768px) {
  .card-320px { padding: 32px; }
}

After (11 values converted, 2 hairlines and 1 PX value kept)

/* Card, 16px root */
.card-320px {
  max-width: 20rem;
  padding: 1.5rem 1.25rem;
  margin: 0 auto 2rem;
  border: 1px solid #d0d7de;
  border-radius: 0.75rem;
  font: 0.9375rem/1.5rem "Inter", sans-serif;
  background: url("img/bg-64px.png") no-repeat;
}
.card-320px h2 {
  font-size: 1.375rem;
  letter-spacing: -0.5px;
  width: calc(100% - 0rem);
  outline-offset: 2PX;
}
@media (min-width: 48em) {
  .card-320px { padding: 2rem; }
}
  • Converted: lengths in declaration values (padding, margin, font, width, calc() and translate() arguments, custom properties and Sass or Less variables), plus @media queries.
  • Never touched: selectors (so .card-320px keeps its name), comments, quoted strings, everything inside url(), @supports and @container queries, and @import lines.
  • Hairlines: with the option on, 1px and smaller (including -0.5px) stay in px.
  • PX in capitals is left alone, the usual way to mark a value that must stay in pixels.
  • Zero becomes a plain 0, except inside calc() and other functions, in the flex shorthand and in variables, where a unitless zero would change the meaning or break the maths, so it becomes 0rem.

The px fallback option writes the original declaration in front of each converted one, for very old browsers that don't understand rem:

h1 {
  font-size: 32px;
  font-size: 2rem;
  margin-bottom: 1px;
  margin-bottom: 0.0625rem;
}

What it can't do: values inside quotes, such as inline styles in HTML or JavaScript style objects, are treated as strings and skipped, so remove the quotes first. It doesn't evaluate Sass or Less maths, so a px value you build from a variable in a calculation stays as you wrote it.

Media queries: em, and always against 16px

Media queries are evaluated before any of your CSS applies, so html { font-size: 62.5% } has no effect on them. The CSS Media Queries specification (W3C, Media Queries Level 4) says relative units in a query are based on the initial font size, which is the browser default: 16px unless the reader changed it. That is why the converter divides breakpoints by 16 whatever root you set, so min-width: 768px becomes min-width: 48em. For a reader with a 20px default, that breakpoint moves to 960px, keeping their larger text in a layout wide enough for it.

Tailwind CSS spacing and font sizes in px and rem

Tailwind sizes its spacing utilities (p-*, m-*, gap-*, w-*, h-* and more) in steps of 0.25rem. In Tailwind v4 any multiple of 0.25 works as a step, so p-13 is 3.25rem; v3 ships the fixed scale below. The px column assumes the 16px root set above, because the classes are defined in rem.

Steprempx
px1px1
0.50.125rem2
10.25rem4
1.50.375rem6
20.5rem8
2.50.625rem10
30.75rem12
3.50.875rem14
41rem16
51.25rem20
61.5rem24
71.75rem28
Steprempx
82rem32
92.25rem36
102.5rem40
112.75rem44
123rem48
143.5rem56
164rem64
205rem80
246rem96
287rem112
328rem128
369rem144
Steprempx
4010rem160
4411rem176
4812rem192
5213rem208
5614rem224
6015rem240
6416rem256
7218rem288
8020rem320
9624rem384
Font size classrempx
text-xs0.75rem12
text-sm0.875rem14
text-base1rem16
text-lg1.125rem18
text-xl1.25rem20
text-2xl1.5rem24
text-3xl1.875rem30
text-4xl2.25rem36
text-5xl3rem48
text-6xl3.75rem60
text-7xl4.5rem72
text-8xl6rem96
text-9xl8rem128

Each text size class also sets a line height. For a size that isn't on the scale, use an arbitrary value such as text-[1.375rem] or p-[52px]; the converter suggests both.

Fluid typography with clamp()

Instead of jumping between sizes at breakpoints, a fluid size grows steadily with the screen. The calculator draws a straight line between two points and works out the clamp() for it:

slope     = (24 − 16) ÷ (1280 − 320) = 0.008333
preferred = (16 − 0.008333 × 320)px + 0.8333vw = 0.8333rem + 0.8333vw
result    = clamp(1rem, 0.8333rem + 0.8333vw, 1.5rem)

That heading is 16px at 320px wide, 20px at 800px wide, 24px at 1280px wide and 24px at 1600px wide: it stops growing at the largest size. Two accessibility rules keep fluid text safe. Write the bounds and the preferred value's fixed part in rem, so the text still responds to the reader's font size setting. And keep the largest size at no more than 2.5 times the smallest: in his analysis for Smashing Magazine (November 2023), Maxwell Barvian showed that within that ratio, browser zoom can always reach 200%, the level WCAG 2 success criterion 1.4.4 (Resize Text) requires. The calculator warns you when a font size breaks that limit.

Accessibility: why rem matters

Zoom and the default font size are different tools. Zoom (Ctrl or ⌘ and +) scales the whole page, px included. The font size setting in Chrome, Edge, Firefox and others changes only the root font size, so only text sized in rem, em or % responds. People who need larger text often prefer the setting because it applies to every site and keeps the layout's proportions. It isn't rare: in a 2018 analysis of Internet Archive visitors, Evan Minto found about 3% browsing with a default other than 16px, more than many browsers' market share at the time. Sizing text in px quietly overrides those readers' choice; the demo above shows the difference.

More CSS and front-end tools

Building the rest of the style? The CSS box shadow generator makes layered, smooth and neumorphic shadows with Tailwind classes, the color converter turns HEX into RGB, HSL or OKLCH and checks contrast, and the color palette generator exports a scheme as CSS variables or a Tailwind config. When the stylesheet is done, shrink it with the CSS minifier, make site icons with the favicon generator, and test a selector pattern in the regex tester.

Frequently asked questions

How do I convert px to rem?

Divide the pixel value by the root font size. With the browser default of 16px, rem = px ÷ 16, so 24px is 1.5rem, 14px is 0.875rem and 12px is 0.75rem. If your CSS sets html { font-size: 10px } or 62.5%, divide by 10 instead. Type a value in the converter and set the root size; the rem and em values update as you type.

What is 16px in rem?

1rem, as long as the root font size is the browser default of 16px. That is why 16 is the number to divide by in almost every px to rem calculation. Other common sizes: 8px = 0.5rem, 12px = 0.75rem, 14px = 0.875rem, 18px = 1.125rem, 20px = 1.25rem, 24px = 1.5rem and 32px = 2rem. If the html element's font size changes, so does the size of 1rem.

How do I convert rem to px?

Multiply by the root font size: px = rem × 16 by default, so 1.5rem is 24px and 0.875rem is 14px. Type in the REM box to convert that way, or switch the stylesheet converter to rem → px to turn a whole file of rem values back into pixels.

What is the difference between rem and em?

rem is relative to the root (html) element's font size, so 1.5rem is the same size everywhere on the page. em is relative to the element's own font size, which for the font-size property itself means the parent's font size. That makes em compound when elements nest: a list at 1.2em inside another list at 1.2em ends up 1.44 times the base size. Use rem for sizes that should stay consistent and em for things that should scale with their own text, such as a button's padding.

Should I use px or rem for font size?

Use rem. Browsers let people choose a larger default text size, and text set in rem, em or % follows that choice while text set in px ignores it. In a 2018 analysis of Internet Archive visitors, Evan Minto found that about 3% had a default font size other than 16px. Page zoom enlarges px and rem alike, so the difference only shows for people who use the font size setting, which is exactly who needs bigger text. px is still fine for details that shouldn't grow with text, such as 1px borders.

Should media queries use em, rem or px?

Inside a media query, em and rem both mean the browser's default font size (16px unless the user changed it), never your html font size: the CSS Media Queries specification bases relative units on the initial value, not on your styles. So 48em is 768px for most visitors and grows for someone with a larger default, which stops large text being squeezed into a narrow layout. em has long been the usual recommendation because older browsers treated rem and px breakpoints inconsistently. px breakpoints are simpler but ignore the font size setting. The converter writes em by default.

What is the 62.5% trick?

Setting html { font-size: 62.5% } makes 1rem equal 10px (62.5% of the 16px default), so 24px is simply 2.4rem. It keeps rem arithmetic easy and still respects the visitor's font size setting. The catch is that everything relying on the 16px default shrinks: you have to set body back to 1.6rem, and third-party widgets written for a 16px root render smaller. To convert for a 62.5% project, set the root size to 10.

Why doesn't changing the font size on body change my rem values?

Because rem always refers to the root element, html, never to body. Set the font size on html (or :root) to change what 1rem means. A font size on body only affects em values and inherited text inside it.

How do I convert px to rem in Tailwind CSS?

Tailwind's spacing scale is in rem. Each step is 0.25rem, which is 4px at the default 16px root, so p-4 is 1rem (16px) and p-6 is 1.5rem (24px). Tailwind v4 accepts any multiple of 0.25, so p-13 gives 3.25rem (52px); v3 has a fixed scale, so values that aren't on it need brackets, like p-[52px]. Font sizes run from text-xs (0.75rem) to text-9xl (8rem). The converter shows the matching classes for whatever value you type.

How do I convert a whole CSS file from px to rem?

Paste it into the stylesheet converter or open the file. It converts px in declaration values only, leaves selectors, comments, strings and url() untouched, can keep 1px borders in px, writes media queries in em, and lists every change in the Changes view before you copy or download the result. It reads CSS, SCSS and Less. In a project with a build step, a PostCSS plugin such as postcss-pxtorem can do the conversion on every build instead.

What does clamp() do for font sizes?

clamp(minimum, preferred, maximum) uses the preferred value but never goes below the minimum or above the maximum. With a preferred value such as 0.8333rem + 0.8333vw, text grows smoothly from 16px on a 320px wide screen to 24px on a 1280px wide screen and stops there. Keeping a rem part in the preferred value means the text still responds to zoom and the font size setting; a value made only of vw doesn't. Keep the maximum at no more than 2.5 times the minimum so zooming can still double the text.

Should borders and shadows be in px or rem?

Hairline borders are usually left in px. A 1px border is a visual detail rather than text, and it stays a crisp single line however large someone sets their default font, while 0.0625rem would thicken along with the text. That's why the stylesheet converter can keep values of 1px and below in px. Thicker borders, outlines and shadows can go either way; to keep a particular value in px, write it as PX in capitals and the converter leaves it alone.

Advertisement