How to Convert Px to Em (Formula, Chart & Examples)
To convert px to em, divide the pixel value by the base font size. With the browser default of 16px, 24px becomes 24 ÷ 16 = 1.5em. If you want the result instantly, use our Pixels to EM Converter.
Table of Contents
Px to Em Formula
The formula is simple:
- em = px ÷ base font size
- px = em × base font size
Most browsers use a default base font size of 16px. So 14px is 14 ÷ 16 = 0.875em, 20px is 1.25em, and 10px is 0.625em.
Px to Em Conversion Chart (16px Base)
| Pixels (px) | Em |
|---|---|
| 8px | 0.5em |
| 10px | 0.625em |
| 12px | 0.75em |
| 14px | 0.875em |
| 16px | 1em |
| 18px | 1.125em |
| 20px | 1.25em |
| 24px | 1.5em |
| 28px | 1.75em |
| 32px | 2em |
| 40px | 2.5em |
| 48px | 3em |
What Is the Difference Between Px, Em and Rem?
- px is a fixed unit. It does not depend on any other element.
- em is relative. For font-size it is relative to the parent font size. For other properties, such as padding and margin, it is relative to the font size of the element itself.
- rem is relative to the font size of the root html element, so it stays the same wherever you use it.
The Em Compounding Problem
Because em depends on the parent, nested elements multiply. If the root is 16px and both a parent and its child use font-size 1.2em, the parent becomes 19.2px and the child becomes 19.2 × 1.2 = 23.04px.
html { font-size: 16px; }
.parent { font-size: 1.2em; } /* 19.2px */
.child { font-size: 1.2em; } /* 23.04px */
This is the main reason many developers prefer rem for font sizes.
When to Use Em, Rem or Px
- Use rem for font sizes and global spacing, because the value is predictable everywhere.
- Use em for components whose spacing should grow with their own text, such as button padding.
- Use px for thin details such as borders and fine shadows. You can also create shadows visually with our CSS Box Shadow Generator.
Why Not Use Px for Font Size?
Most browsers let users set a default font size in their settings. Font sizes written in px ignore that setting, while em and rem follow it. Using relative units helps people who need larger text.
How to Convert Px to Em Quickly
- Open the Pixels to EM Converter.
- Enter the pixel value and your base font size (16 by default).
- Copy the em value into your CSS.
In CSS you can also let the browser do the math, for example font-size: calc(24 / 16 * 1rem);.
Frequently Asked Questions
How do I convert 16px to em?
With a 16px base, 16px equals 1em, because 16 ÷ 16 = 1.
What is 1em in px?
It depends on the font size it is relative to. With the default 16px, 1em is 16px.
Is em or rem better?
For most font sizes, rem is easier because it does not compound. Em is better when an element should scale with its own text size.
Is 1em equal to 1rem?
Only when the parent font size is the same as the root font size.
Final Thoughts
To convert px to em, divide by the base font size, usually 16. Use rem for most text and spacing, em for self-scaling components, and px only for fine details.
