PX to EM Converter
Free px to em converter. Enter any pixel value, set your parent font size, and get the em value instantly. Formula: em = px ÷ parent font size. No signup needed.
Formula
em = px ÷ parent font size
Quick Reference Table
How EM Units Actually Work
The em unit is one of the oldest relative units in CSS. It takes its name from typography, where an "em" was the width of the capital letter M in the current typeface. In CSS, 1em simply equals the computed font-size of the element's parent. MDN Web Docs defines it as the computed font-size of the element on which it is used.
This parent-relative behavior is what makes em powerful and, at the same time, confusing. When you write padding: 1.5em on a button, the actual padding depends on what font size that button has. Change the font size, and the padding changes with it. This is exactly the behavior you want for components that need to scale as a unit.
But here is where it gets tricky: when you use em for the font-size property itself, it references the parent's font size, not the element's own size. And when you nest multiple levels, each em multiplies on top of the previous one. This is called the "cascade effect," and it is the main reason many developers prefer rem for font sizes.
The EM Cascade Effect (Visualized)
This is the number one thing that trips people up with em. Watch how the same 1.2em declaration produces different pixel values at each nesting level:
font-size: 16px
font-size: 1.2em
font-size: 1.2em
font-size: 1.2em
Each level multiplies: 16 x 1.2 = 19.2, then 19.2 x 1.2 = 23.04, then 23.04 x 1.2 = 27.65. The same CSS declaration produces a bigger font at every level. This is why rem is safer for font sizes in complex layouts.
EM vs REM: When to Use Each
Practical Code Examples
.btn {
font-size: 1rem; /* base: 16px */
padding: 0.5em 1.25em; /* 8px 20px - scales with font */
border-radius: 0.25em; /* 4px - scales with font */
}
.btn-lg {
font-size: 1.25rem; /* 20px */
/* padding automatically becomes 10px 25px */
/* border-radius becomes 5px */
/* Everything scales proportionally! */
}
.btn-sm {
font-size: 0.875rem; /* 14px */
/* padding becomes 7px 17.5px */
/* No need to redeclare padding or radius */
}.icon {
width: 1em; /* Same size as the text */
height: 1em;
}
/* Icon in a heading = big icon */
h1 { font-size: 2rem; }
h1 .icon { /* 32px x 32px */ }
/* Icon in body text = small icon */
p { font-size: 1rem; }
p .icon { /* 16px x 16px */ }/* This causes the cascade problem */
.list { font-size: 0.9em; }
.list .list { font-size: 0.9em; }
/* Second list: 0.9 x 0.9 = 0.81em of root */
/* Third list: 0.81 x 0.9 = 0.729em of root */
/* Text keeps shrinking! */
/* Fix: use rem for font-sizes */
.list { font-size: 0.9rem; }
/* Now every nested list is 0.9rem, period. */The Modern Approach: REM for Size, EM for Space
Most senior developers today follow a simple pattern: use rem for all font-size declarations (to avoid the cascade problem), and use em for padding, margin, and gaps within components (so spacing scales proportionally with text).
This gives you the best of both worlds. Your text sizes are predictable and accessible (rem), while your component spacing adapts automatically when you create different size variants (em). A large button with bigger text automatically gets more padding. A small label with tiny text gets tighter spacing. All from a single CSS class.
If you are just getting started with relative units, begin with rem everywhere. Once you are comfortable, start using em for padding and margins inside reusable components. That is the pattern most CSS frameworks like Tailwind and Bootstrap follow internally.