REM vs EM vs PX in CSS: Which Unit to Use and How to Convert

How rem, em and px differ, why rem respects user font settings, the px to rem formula, the 62.5% trick and when pixels are still the right choice.

Updated September 29, 2026 6 min read

Use the free PX to REM ConverterConvert pixels to rem or em and back with any base font size

The design file says the heading is 28px, the card padding is 24px and the body text is 16px. You could type those values straight into your CSS, and the page would look right on your screen. But a reader who has set a larger default font size in their browser, which many people with low vision do, would see your text stay stubbornly small while everything around it ignores their preference.

This guide explains how px, em and rem behave, why rem has become the default choice for type and spacing, how to convert values quickly, and the cases where pixels are still the better tool.

Three units, three reference points

px

A CSS pixel is an absolute unit as far as your stylesheet is concerned. font-size: 16px is 16px regardless of anything else on the page. (On high-density screens one CSS pixel covers several device pixels, but that does not change how you write CSS.)

Pixels do scale with browser zoom. They do not scale with the default font size setting in the browser's preferences. That difference is the heart of the rem argument.

em

em is relative to the font size of the current element, and for the font-size property itself, to the parent's font size. If a parent has font-size: 20px, then 1.5em inside it is 30px.

That makes em useful for things that should grow with the local text, such as padding on a button or the gap between an icon and its label. It also makes em compound: nested lists with font-size: 0.9em get smaller at every level.

rem

rem means "root em": it is relative to the font size of the root html element, no matter how deeply the element is nested. With the browser default of 16px, 1rem is 16px, 1.5rem is 24px and 0.875rem is 14px.

Because the root font size follows the user's browser setting (unless your CSS overrides it with a pixel value), everything sized in rem scales in proportion when a reader asks for bigger text.

The conversion formula

rem = px ÷ root font size
px  = rem × root font size

With the default 16px root:

px rem
12 0.75
14 0.875
16 1
18 1.125
20 1.25
24 1.5
32 2
48 3

For em, use the same formula but divide by the parent element's font size instead of the root.

Convert values with the tool

The PX to REM Converter handles single values, a reference table and whole CSS blocks.

  1. Open the PX to REM Converter. Type into Pixels (px) to get the rem value, or into REM / EM to get pixels. Each field has a copy button that adds the unit.
  2. Set Root / parent font size (px) if your base is not 16. Use the root size for rem, or the parent's size when you are working out em.
  3. Adjust Decimal places (0 to 8) if you want shorter values such as 0.875 rather than long fractions.
  4. Click any tile in the Quick reference grid to load that pixel value.
  5. To migrate existing styles, paste CSS into Convert a CSS block (px → rem). Every px value is converted and shown under Converted CSS. Leave Keep 1px (borders) switched on so hairline borders stay at 1px.

A value of 0px becomes plain 0, since zero needs no unit.

A practical unit strategy

Most modern stylesheets settle on a mix like this:

html {
  /* no pixel value here, so the user's default font size is respected */
  font-size: 100%;
}

body {
  font-size: 1rem;
  line-height: 1.5;
}

h1 {
  font-size: 2.25rem;
  margin-block-end: 1rem;
}

.card {
  padding: 1.5rem;
  border: 1px solid #d0d7de;
  border-radius: 0.5rem;
}

.button {
  font-size: 0.875rem;
  padding: 0.5em 1em; /* em: scales with the button's own text */
}
  • rem for font sizes, spacing between blocks, and layout widths that should grow with text.
  • em for padding and gaps that should track the element's own font size, and for media queries.
  • px for borders, hairlines, box-shadow offsets and small decorative details that should not grow.
  • Unitless line-height, so it scales with whatever font size the element ends up with.

Media queries in em

Breakpoints written in em (for example @media (min-width: 48em)) respond to the user's font-size setting, so a user with very large text gets the narrower, single-column layout sooner. In media queries, em and rem both refer to the browser's initial font size, not your html rule.

The 62.5% trick and why to think twice

Some teams set html { font-size: 62.5%; } so that 1rem equals 10px with the default setting, making mental maths easy (1.6rem = 16px). It still respects user preferences, because it is a percentage. The downsides are that every component must now set its own font size or text will render at 10px, and third-party widgets that assume 1rem = 16px will look tiny. With a converter at hand, the maths shortcut matters less, so many teams keep the default 100%.

Avoid html { font-size: 16px; }. A pixel value on the root overrides the user's setting and cancels the main benefit of rem.

Pitfalls and troubleshooting

Everything became tiny or huge after conversion

Check the root font size you converted with. If your site sets html { font-size: 62.5% } and you converted with a 16px base, every value will be 60% too small. Set the Root / parent font size field to 10 in that case.

Nested em values keep shrinking

That is em compounding. Switch the font-size to rem, and keep em only for properties like padding that should follow the element's own text.

Borders turn into 0.0625rem

A 1px border converted to rem may render as a blurred or disappearing line at some zoom levels. Keep borders in px.

Designs are delivered in pixels

That is normal; design tools work in px. Convert while implementing, and keep a shared scale (for example 4, 8, 12, 16, 24, 32, 48) so spacing stays consistent. Layout tools such as the CSS grid generator accept rem values for column and row sizes, and the box shadow generator and border radius generator output the pixel details that are best left as px. Run the finished stylesheet through the CSS formatter to tidy it.

Frequently asked questions

How many pixels is 1rem?

It equals the root element's font size, which is 16px in all major browsers unless the user or your stylesheet changes it.

Is rem better than px for accessibility?

For font sizes, yes. Text in rem follows the user's default font size setting, while px text only responds to zoom. Both respond to page zoom.

When should I use em instead of rem?

Use em when a value should scale with the element's own font size, such as a button's padding, an icon next to text, or media query breakpoints.

How do I convert px to rem?

Divide the pixel value by the root font size. With the default 16px, 24px ÷ 16 = 1.5rem.

Should borders be in rem?

Usually not. Thin borders and shadows are better in px so they stay crisp and do not grow with text size.

Try it now: PX to REM Converter

Loading tool…