Convert px to em
The em unit is relative to the font size of the parent element, which makes it useful for component-scoped sizing that scales with its context. This converter turns a pixel value into the equivalent em for a given parent font size, so you can move a design from fixed pixels to relative CSS units.
How it works
The conversion divides the pixel value by the parent element’s font size:
em = px ÷ parent font size (px)
px = em × parent font size (px)
The parent font size — not the root — is the divisor, because ems inherit and compound through nested elements. The default parent of 16px matches the browser’s usual root size.
Example
Convert 24px with a 16px parent:
- 24 ÷ 16 = 1.5em
If the parent font size were 20px instead, the same 24px would be 24 ÷ 20 = 1.2em.
| Pixels | Parent | Result |
|---|---|---|
| 24px | 16px | 1.5em |
| 12px | 16px | 0.75em |
| 24px | 20px | 1.2em |
em versus rem: choosing the right one
The most common source of confusion in CSS typography is when to use em versus rem. The difference is what they are relative to.
em is relative to the computed font size of the element’s parent. This makes it powerful for components that should scale proportionally: if the parent font size changes — perhaps because the user has a larger base font set, or you override it in a media query — the child’s size scales with it automatically.
rem is relative to the root element’s font size (the html element). It does not compound. This makes it predictable across nesting and is the better choice for spacing, layout, and any value that should stay consistent regardless of where in the DOM it appears.
Where em shines
- Padding and margins inside a component — for example, a button whose horizontal padding is
0.75emwill scale naturally if the button’s font size increases, keeping the proportions intact. - Line height on headings —
line-height: 1.2emkeeps the spacing proportional to the heading’s own size, not the page root. - Icon sizes next to text — an SVG icon set to
1emwill always match the adjacent font size without hard-coding a pixel value.
Where rem is safer
- Global spacing tokens (gutters, column widths, section padding)
- Base text sizes on body copy —
font-size: 1remonptags means a user’s browser preference is always respected without compounding.
The compounding trap
When you nest em-sized elements, the sizes multiply. For example:
.outer { font-size: 1.2em; } /* 16 × 1.2 = 19.2px */
.inner { font-size: 1.2em; } /* 19.2 × 1.2 = 23.04px */
This compounding is why deeply nested em sizes can produce unexpectedly large or small text. Enter the actual parent size into this converter whenever you are inside nested components — do not assume 16px.
Enter your numbers and the result updates instantly, all in your browser.