What Is the Difference Between PX, REM and EM? CSS Units, a Conversion Table and Which to Use When
Updated: November 6, 2026 · AracMerkezi
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
| px | rem (base 16) | rem (base 20) |
|---|---|---|
| 8 px | 0.5 rem | 0.4 rem |
| 12 px | 0.75 rem | 0.6 rem |
| 14 px | 0.875 rem | 0.7 rem |
| 16 px | 1 rem | 0.8 rem |
| 18 px | 1.125 rem | 0.9 rem |
| 20 px | 1.25 rem | 1 rem |
| 24 px | 1.5 rem | 1.2 rem |
| 32 px | 2 rem | 1.6 rem |
| 48 px | 3 rem | 2.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.
- At the default 16 px base, the heading is 1.5 × 16 = 24 px and the label is 24 px; they are the same.
- If the user sets the browser font size to 20 px, the heading becomes 1.5 × 20 = 30 px.
- 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.
- First element: 16 × 1.25 = 20 px.
- The second element inside it, relative to the first one's size: 20 × 1.25 = 25 px.
- 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:
- With 14 px text, the vertical padding is 0.75 × 14 = 10.5 px and the horizontal padding is 1.5 × 14 = 21 px.
- With 18 px text, the vertical padding is 13.5 px and the horizontal padding is 27 px.
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?
| Use | Recommended unit |
|---|---|
| Font size and spacing | rem |
| Thin borders (1 px) and shadows | px |
| Values proportional to the inside of a component | em |
| Line height | Unitless number (for example 1.5) |
| Media query breakpoints | em 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
- Root element (html): The topmost element on the page; rem is tied to its font size.
- Base size: The root's font size; 16 px by default in most browsers.
- Computed value: The result the browser arrives at after resolving em, rem and percentages to pixels.
- Unitless multiplier: A number with no unit, as in line height, that passes to child elements as a multiplier.
Common mistakes
- Writing all sizes in px and ignoring the user's font-size setting.
- Using em in nested elements without accounting for compounding.
- Assuming the root size is 16 px; the user or your code may have changed it.
- Using rem for borders and shadows and causing thin lines to blur across screens.
- 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
- How to Convert HEX to RGB Color Codes: Step-by-Step Examples – How to convert a HEX color code to RGB and back: hexadecimal basics, short and 8-digit HEX, darkening math and verified JavaScript and Python snippets.
- How to Choose a Color Palette for a Website: Building a Full Palette From One Color – How to choose a website color palette: build tints, accents and neutrals from one HEX color, with the 60-30-10 rule, contrast values and CSS variables.
- What Is Color Contrast Ratio? A Step-by-Step WCAG AA and AAA Calculation with Example Colors – How is color contrast ratio calculated? WCAG AA and AAA thresholds (4.5:1, 3:1, 7:1), the luminance formula, worked color examples and tips.
- How to Make Fluid Font Sizes with CSS clamp(): Formula, Ready Values and Glassmorphism – How is CSS clamp(min, preferred, max) calculated? The formula for fluid type between two screen widths, 3 worked examples, rem and accessibility notes.
- How to Make Glassmorphism (Frosted Glass Effect) With CSS – How do you make a frosted glass effect with CSS? backdrop-filter, semi-transparent background, border and shadow values, plus support and contrast tips.
This article is for general information only and is not legal, financial or medical advice. We are not an official institution.