TR

Home / Guides / What Is the Difference Between PX, REM and EM? CSS Units, a Conversion Table and Which to Use When

What Is the Difference Between PX, REM and EM? CSS Units, a Conversion Table and Which to Use When

Updated: November 6, 2026 · AracMerkezi

▶ Open PX REM EM Converter

There are three units you often meet when writing sizes in CSS: px, rem and em. The right choice lets your site work properly on different screens and with user settings. In this guide we do not stop at defining the units; we show with numbers what happens when a user changes the browser font size, how em values compound in nested elements, and how the padding of a button scales with em.

Pixel (px)

It is a fixed unit. 16 px is the same size under all conditions. It is easy to understand but does not take the user's browser font-size setting into account.

rem

It is relative to the font size of the root element (html). Because the browsers' default size is 16 px, 1 rem = 16 px. When the user enlarges the browser font size, areas written in rem grow proportionally. That is why rem is preferred for font size and spacing from an accessibility standpoint.

em

It is relative to the font size of the element it is on (or its parent). In nested elements the value is multiplied cumulatively, which sometimes causes unexpected results. It is more useful for sizing inside a component (for example, making a button's padding follow the button's font size).

Conversion formula

rem = px ÷ base size (usually 16)

px = rem × base size

Conversion table: 16 px and 20 px base

pxrem (base 16)rem (base 20)
8 px0.5 rem0.4 rem
12 px0.75 rem0.6 rem
14 px0.875 rem0.7 rem
16 px1 rem0.8 rem
18 px1.125 rem0.9 rem
20 px1.25 rem1 rem
24 px1.5 rem1.2 rem
32 px2 rem1.6 rem
48 px3 rem2.4 rem

The same px value corresponds to a different rem depending on the base size, because rem depends on the root's size. That is why the tool has a "base font size" field.

Example 1: If the user enlarges the font size

Suppose you write font-size: 1.5rem on a heading and font-size: 24px on a label.

  1. At the default 16 px base, the heading is 1.5 × 16 = 24 px and the label is 24 px; they are the same.
  2. If the user sets the browser font size to 20 px, the heading becomes 1.5 × 20 = 30 px.
  3. The label stays at 24 px; the user's preference is not reflected in the label.

Being able to enlarge text by at least 200 percent is one of the WCAG accessibility criteria; rem adapts to this need more easily than px. For accessibility related to color, take a look at the color contrast ratio guide.

Example 2: How does em compound when nested?

Let the body font size be 16 px, and write font-size: 1.25em on three nested elements.

  1. First element: 16 × 1.25 = 20 px.
  2. The second element inside it, relative to the first one's size: 20 × 1.25 = 25 px.
  3. The third element: 25 × 1.25 = 31.25 px.

Although all three elements write the same value, the sizes are different. If you had written 1.25rem in the same structure, all three would be 20 px. That is why giving font size in em in nested lists or menus can lead to surprises.

Example 3: Scaling a button's padding with em

If you write padding: 0.75em 1.5em on a button, the padding follows the button's own font size:

To make the button bigger, it is enough to change only the font size; the padding stays proportional. This is the real strength of em for proportional values inside a component.

Example 4: The "62.5%" trick and what to watch for

In some projects font-size: 62.5% is written on the root; since 16 × 0.625 = 10 px, 1 rem = 10 px, which makes calculations like 2.4 rem = 24 px easier. However, because this method also shrinks the user's font-size preference, you need to raise the size back by giving the body text a value such as 1.6rem; if you do not, the text stays small.

Which one when?

UseRecommended unit
Font size and spacingrem
Thin borders (1 px) and shadowspx
Values proportional to the inside of a componentem
Line heightUnitless number (for example 1.5)
Media query breakpointsem or rem (768 px = 48 em)

A unitless number is preferred for line height because it passes to child elements as a multiplier. With 16 px text, line-height: 1.5 is 24 px; in an inner element with 20 px text the same multiplier gives 30 px. If you had written line-height: 24px, the inner element would also be fixed at 24 px.

Quick check in the browser

To see the real equivalent of a value, select the element in the browser's developer tools and look at the "computed" tab; there, rem and em values appear converted to pixels. That way you can compare the number you calculated by hand with the real one. Raising the browser font-size setting from 16 px to 20 px and reloading the page is also the easiest way to see whether elements using rem really grow.

Short glossary

Common mistakes

  1. Writing all sizes in px and ignoring the user's font-size setting.
  2. Using em in nested elements without accounting for compounding.
  3. Assuming the root size is 16 px; the user or your code may have changed it.
  4. Using rem for borders and shadows and causing thin lines to blur across screens.
  5. Forgetting to enlarge the body text again after applying the 62.5% trick.

When to use it and its limits

Because rem depends on the root size, it is suitable for general scaling; but for icons, lines or image sizes that need pixel precision, px is more predictable. For a fluid font size (one that changes with screen width) you need clamp(); for details, see the CSS clamp() guide. The numbers on this page come from multiplication and are independent of the browser; still, test the real appearance in your target browser.

For quick conversion you can use the PX REM EM Converter. The CSS Box Shadow Generator is also useful for shadow values. For colors, you can look at the HEX and RGB guide.

Frequently asked questions

How many pixels is 1 rem?

Because the browser's default base size is 16 px, 1 rem = 16 px. If the root font size changes, the equivalent changes too.

Should I use rem or px?

rem is recommended for font size and spacing, and px for thin borders.

What is the difference between em and rem?

em is relative to the font size of the element it is on, and rem to the root element's font size.

Tools mentioned in this guide

More guides

This article is for general information only and is not legal, financial or medical advice. We are not an official institution.