Design / Diseño

Px to Em Converter

Enter a pixel value and the parent font-size. We return the em equivalent.

Instant🔒In your browserNo signup
Live

Quick table

pxem

What em is

em is a unit relative to an element's font-size. When you set padding: 1em, the padding equals the font-size of the element (or parent in some contexts). Unlike rem, which is always relative to the root, em depends on context.

Formula

em = px / parent font-size

If the parent has font-size: 16px, then 24px = 1.5em. If the parent is 20px, then 24px = 1.2em.

When em is the right choice

The classic use of em is for components with their own typographic scale. A button: if you set padding in em, scaling the button size by changing font-size also scales padding proportionally. With rem or px, padding is fixed and proportions break.

.btn {
  font-size: 1rem;
  padding: 0.75em 1.5em; /* scales with font-size */
}
.btn--lg {
  font-size: 1.25rem; /* padding grows automatically */
}

The composition problem

em compounds: nested em multiplies. If you have section { font-size: 1.2em } and inside p { font-size: 1.2em }, the paragraph ends up at 1.44em of the root. Nest three levels and sizes become unpredictable.

That is why many modern systems prefer rem for typography and reserve em for spacing inside specific components where "scale with context" is exactly the desired behavior.

em for media queries

Media queries in em (vs px) respond better to user text zoom. If someone increases the browser font-size, em-based breakpoints fire earlier, keeping the layout responsive even for zoomed users. A subtle but real accessibility win.

Practical use cases

  • Buttons: em padding so it scales with size variants.
  • Inputs: same logic.
  • Cards: inner padding proportional to content.
  • Nested lists: indentation that respects parent item size.
  • Inline icons: width: 1em matches the text line size.

When NOT to use em

For global typography (h1, body, etc.): rem is more predictable. For page-level spacing (grid gaps, section margins): rem too. em shines in self-contained components, not macro layout.

Summary

Use rem as the default. Use em when you want something to scale with the surrounding type context. Always check computed values in DevTools when something feels off.

FAQ

em vs rem?

em is relative to the element (or parent). rem always to root.

When to use em?

For spacings that scale with the component font-size.

Does em compose?

Yes — nested em values multiply. Be careful in deep structures.

Was this generator useful?