Pixels to em

Pixels to em and back for a given parent size, with the compounding shown.

24px ÷ 16 = 1.5em (16px parent size)

The same value in every unit

  • points

    18pt

    24px ÷ 1.3333 = 18pt (96 px per inch ÷ 72)

  • inches

    0.25in

    24px ÷ 96 = 0.25in (96 px per inch)

  • centimetres

    0.635cm

    24px ÷ 37.7953 = 0.635cm (96 px per inch ÷ 2.54)

  • millimetres

    6.35mm

    24px ÷ 3.7795 = 6.35mm (96 px per inch ÷ 25.4)

  • picas

    1.5pc

    24px ÷ 16 = 1.5pc (96 px per inch ÷ 6)

In short

Divide pixels by the parent element's font size to get em: 24px is 1.5em inside a 16px parent and 1.2em inside a 20px one. Multiply em by the parent size to get pixels. The parent size is the part people forget, and the reason em can surprise you.

The formula

em = px ÷ parent font size
px = em × parent font size
nested: size = base × em × em × …

Reference tables

Computed by the same code as the converter above.

Pixels to em
pixelsParent 14pxParent 16pxParent 20px
8px0.5714em0.5em0.4em
10px0.7143em0.625em0.5em
12px0.8571em0.75em0.6em
14px1em0.875em0.7em
16px1.1429em1em0.8em
18px1.2857em1.125em0.9em
20px1.4286em1.25em1em
24px1.7143em1.5em1.2em
28px2em1.75em1.4em
32px2.2857em2em1.6em
40px2.8571em2.5em2em
48px3.4286em3em2.4em
Em to pixels
emParent 14pxParent 16pxParent 20px
0.5em7px8px10px
0.75em10.5px12px15px
0.875em12.25px14px17.5px
1em14px16px20px
1.125em15.75px18px22.5px
1.25em17.5px20px25px
1.5em21px24px30px
2em28px32px40px
3em42px48px60px

Em compounds, and that is both its use and its trap

An em is the font size of the element it is used on, and for font-size itself that means the parent's. Nest three lists that each set font-size: 1.2em and the innermost text is 16 × 1.2 × 1.2 × 1.2 = 27.648px, not 19.2px. That is the classic em bug, and it is why rem was added to CSS.

The same behaviour is what makes em right for some jobs. Padding in em on a button grows with the button's own text, so a large button and a small one keep the same proportions from one rule. An icon sized at 1em matches whatever text it sits beside. Use em when something should scale with its own text, and rem when it should scale with the page.

A converter can only answer for a stated parent size, so this one asks for it. If you do not know the parent size, inspect the element in your browser's developer tools: the computed font-size of the parent is the number to use.

Worked examples

Real sizes, with the sums.

Nested lists at 1.2em

You give it

Three levels of ul { font-size: 1.2em } on a 16px page.

You get

19.2px, then 23.04px, then 27.648px. With 1.2rem instead, every level stays at 19.2px.

Button padding that scales with its label

You give it

A 14px label with 10px vertical and 16px horizontal padding.

You get

10 ÷ 14 = 0.7143em and 16 ÷ 14 = 1.1429em. Set the label to 18px and the padding becomes 12.86px and 20.57px without another rule.

Questions people ask

Straight answers. Each one links directly: copy the address after opening it.

How many pixels is 1em?

The font size of the parent element: 16px if nothing on the page changes it, but any ancestor that sets a font size changes the answer.

Why is my em size bigger than I expected?

Because em compounds. If a parent is already 1.2em of its parent, 1.2em inside it is 1.44 times the base. Switch to rem for sizes that should not compound.

When should I use em instead of rem?

For spacing and icons that should scale with their own text, such as button padding or an icon beside a label. For type sizes across a page, rem.

Other unit conversions