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)
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 | rem |
|---|---|
| 1px | 0.0625rem |
| 2px | 0.125rem |
| 3px | 0.1875rem |
| 4px | 0.25rem |
| 5px | 0.3125rem |
| 6px | 0.375rem |
| 7px | 0.4375rem |
| 8px | 0.5rem |
| 9px | 0.5625rem |
| 10px | 0.625rem |
| 11px | 0.6875rem |
| 12px | 0.75rem |
| 13px | 0.8125rem |
| 14px | 0.875rem |
| 15px | 0.9375rem |
| 16px | 1rem |
| 17px | 1.0625rem |
| 18px | 1.125rem |
| 19px | 1.1875rem |
| 20px | 1.25rem |
| 21px | 1.3125rem |
| 22px | 1.375rem |
| 23px | 1.4375rem |
| 24px | 1.5rem |
| 25px | 1.5625rem |
| px | rem |
|---|---|
| 26px | 1.625rem |
| 27px | 1.6875rem |
| 28px | 1.75rem |
| 29px | 1.8125rem |
| 30px | 1.875rem |
| 31px | 1.9375rem |
| 32px | 2rem |
| 33px | 2.0625rem |
| 34px | 2.125rem |
| 35px | 2.1875rem |
| 36px | 2.25rem |
| 37px | 2.3125rem |
| 38px | 2.375rem |
| 39px | 2.4375rem |
| 40px | 2.5rem |
| 41px | 2.5625rem |
| 42px | 2.625rem |
| 43px | 2.6875rem |
| 44px | 2.75rem |
| 45px | 2.8125rem |
| 46px | 2.875rem |
| 47px | 2.9375rem |
| 48px | 3rem |
| 49px | 3.0625rem |
| 50px | 3.125rem |
| px | rem |
|---|---|
| 51px | 3.1875rem |
| 52px | 3.25rem |
| 53px | 3.3125rem |
| 54px | 3.375rem |
| 55px | 3.4375rem |
| 56px | 3.5rem |
| 57px | 3.5625rem |
| 58px | 3.625rem |
| 59px | 3.6875rem |
| 60px | 3.75rem |
| 61px | 3.8125rem |
| 62px | 3.875rem |
| 63px | 3.9375rem |
| 64px | 4rem |
| 65px | 4.0625rem |
| 66px | 4.125rem |
| 67px | 4.1875rem |
| 68px | 4.25rem |
| 69px | 4.3125rem |
| 70px | 4.375rem |
| 71px | 4.4375rem |
| 72px | 4.5rem |
| 73px | 4.5625rem |
| 74px | 4.625rem |
| 75px | 4.6875rem |
| px | rem |
|---|---|
| 76px | 4.75rem |
| 77px | 4.8125rem |
| 78px | 4.875rem |
| 79px | 4.9375rem |
| 80px | 5rem |
| 81px | 5.0625rem |
| 82px | 5.125rem |
| 83px | 5.1875rem |
| 84px | 5.25rem |
| 85px | 5.3125rem |
| 86px | 5.375rem |
| 87px | 5.4375rem |
| 88px | 5.5rem |
| 89px | 5.5625rem |
| 90px | 5.625rem |
| 91px | 5.6875rem |
| 92px | 5.75rem |
| 93px | 5.8125rem |
| 94px | 5.875rem |
| 95px | 5.9375rem |
| 96px | 6rem |
| 97px | 6.0625rem |
| 98px | 6.125rem |
| 99px | 6.1875rem |
| 100px | 6.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);Arbitrary-value class (v3 and v4)
text-[clamp(1rem,0.8333rem_+_0.8333vw,1.5rem)]Custom property
:root {
--fluid-font-size: clamp(1rem, 0.8333rem + 0.8333vw, 1.5rem);
}
h1 {
font-size: var(--fluid-font-size);
}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
- Set the root font size: leave 16 unless your CSS changes the html font size (62.5% means 10).
- Type a value in Pixels, REM or EM; the other two update instantly. Tap a Tailwind class to copy it.
- To convert a file, paste it into Convert a whole stylesheet, pick how to treat hairlines and media queries, and check the Changes view.
- 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
| Unit | Relative to | Grows with the font size setting? | Good for |
|---|---|---|---|
| px | Nothing (a CSS pixel, 1/96 inch) | No (zoom only) | Hairline borders, shadows, small fixed details |
| rem | The html element's font size | Yes | Font sizes, spacing, layout widths: one consistent scale |
| em | The element's own font size (the parent's, for font-size) | Yes | Padding that should scale with its own text, icons beside text |
| % | The parent (font size, or width for widths) | Yes, for font-size | Fluid 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-320pxkeeps its name), comments, quoted strings, everything insideurl(), @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 becomes0rem.
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.
| Step | rem | px |
|---|---|---|
| px | 1px | 1 |
| 0.5 | 0.125rem | 2 |
| 1 | 0.25rem | 4 |
| 1.5 | 0.375rem | 6 |
| 2 | 0.5rem | 8 |
| 2.5 | 0.625rem | 10 |
| 3 | 0.75rem | 12 |
| 3.5 | 0.875rem | 14 |
| 4 | 1rem | 16 |
| 5 | 1.25rem | 20 |
| 6 | 1.5rem | 24 |
| 7 | 1.75rem | 28 |
| Step | rem | px |
|---|---|---|
| 8 | 2rem | 32 |
| 9 | 2.25rem | 36 |
| 10 | 2.5rem | 40 |
| 11 | 2.75rem | 44 |
| 12 | 3rem | 48 |
| 14 | 3.5rem | 56 |
| 16 | 4rem | 64 |
| 20 | 5rem | 80 |
| 24 | 6rem | 96 |
| 28 | 7rem | 112 |
| 32 | 8rem | 128 |
| 36 | 9rem | 144 |
| Step | rem | px |
|---|---|---|
| 40 | 10rem | 160 |
| 44 | 11rem | 176 |
| 48 | 12rem | 192 |
| 52 | 13rem | 208 |
| 56 | 14rem | 224 |
| 60 | 15rem | 240 |
| 64 | 16rem | 256 |
| 72 | 18rem | 288 |
| 80 | 20rem | 320 |
| 96 | 24rem | 384 |
| Font size class | rem | px |
|---|---|---|
| text-xs | 0.75rem | 12 |
| text-sm | 0.875rem | 14 |
| text-base | 1rem | 16 |
| text-lg | 1.125rem | 18 |
| text-xl | 1.25rem | 20 |
| text-2xl | 1.5rem | 24 |
| text-3xl | 1.875rem | 30 |
| text-4xl | 2.25rem | 36 |
| text-5xl | 3rem | 48 |
| text-6xl | 3.75rem | 60 |
| text-7xl | 4.5rem | 72 |
| text-8xl | 6rem | 96 |
| text-9xl | 8rem | 128 |
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.
Related tools
More free, private, browser-based utilities — no upload, no sign-up.