Boneyard Tools

PX to EM Calculator

Convert between px and em using the parent element font-size as the basis. An em is relative to the current element's font-size, so the parent value is what 1em equals here. The default basis is 16px.

How to convert px to em

  1. Pick a direction: px to em, or em to px.
  2. Set the parent font-size that 1em should equal in this context.
  3. Type your value and copy the converted result.

Examples

Convert a pixel size to em

24px at a 16px parent
1.5em

Convert em back to pixels

0.5em at a 20px parent
10px

Frequently asked questions

What is the difference between em and rem?

An em is relative to the font-size of the parent or current element, while a rem is relative to the root font-size on the html element. Because em depends on the parent, the same em value can resolve to different pixel sizes in different parts of a page.

How do I convert px to em?

Divide the pixel value by the parent font-size. With a 16px parent, 24px is 24 divided by 16, which is 1.5em. To go the other way, multiply the em value by the parent font-size.

Why does em compound when elements are nested?

Each em resolves against its own parent. If a parent is set to 1.2em it grows, and a child set to 1.2em multiplies on top of that, so sizes can snowball through nested elements. Rem avoids this by always using the root.

What parent font-size should I use?

Use the computed font-size of the element that the em value applies to, which is usually inherited from its parent. If you are unsure, 16px is the common browser default and a safe starting point.

When should I prefer em over rem?

Em is handy for spacing that should scale with a component's own font-size, such as padding inside a button that grows with its label. Rem is better when you want sizing to stay consistent across the whole page.

Related tools