When you need this conversion
You have pixel values from a design and want them to scale with the text they sit next to. Button padding, the gap between an icon and its label, and the margin under a heading all look best when they grow with the font size. Writing them in em does exactly that.
How em is resolved
The browser takes the element’s computed font size and multiplies. For font-size itself, em refers to the parent font size; for every other property (padding, margin, width), it refers to the element’s own font size. That’s why this converter asks for a parent size: it’s the number that matters.
- 8 px of padding on a 16 px button: 0.5em
- 24 px heading inside 16 px body text: 1.5em
- 12 px caption inside 16 px text: 0.75em
Common mistakes
Nesting em font sizes. Each level multiplies the one above it. Three nested elements at 1.2em end up at 1.728 times the base. If that’s not what you want, use rem for font sizes and keep em for spacing.
Assuming 1 em is always 16 px. It is only 16 px when the parent is 16 px. Inside a 20 px heading, 1 em is 20 px.
For sizes that shouldn’t compound, see pixels to rem. For the reverse, use em to pixels.