πŸ¦‰ UnitOwl

Pixels to Em

1 Pixel (px) = 0.0625Em (em)

By KAMP Inc. / UnitOwl · Last reviewed:

Result
0.0625 em
1 px = 0.0625 em
Ad Slot (horizontal)

How to Convert Pixels to Em?

To convert pixels to em units, divide the pixel value by the parent element's font size (typically 16px for the root). One em is equal to the computed font size of the element. Assuming a 16px base font size (the browser default), 1em = 16px, so 24px = 1.5em and 32px = 2em. The em unit is fundamental to responsive web design because it scales proportionally with text size. Unlike fixed pixel values, em-based sizing adapts when users change their browser font size, making content more accessible. Designers and developers use this conversion daily when translating pixel-perfect mockups into flexible, accessible CSS. Understanding the px-to-em relationship is critical for building layouts that respect user preferences and work across different devices and accessibility settings. It is most useful for component-level sizing, where padding, icons, or nested elements should grow in proportion to the local text size instead of staying fixed. That makes px-to-em conversion a common step when modernizing an older pixel-based stylesheet or turning a static design handoff into a more resilient UI.

How to Convert Pixel to Em

  1. Determine the base font size (usually 16px for the root element).
  2. Divide the pixel value by the base font size to get em.
  3. The formula is: em = px / base-font-size.
  4. With the default 16px base: 1em = 16px, 0.5em = 8px, 2em = 32px.
  5. Important: em is relative to the parent element. If the parent has a different font size, use that instead of 16px.

Real-World Examples

Convert 24px padding to em (base font: 16px).
24 / 16 = 1.5em. The padding will scale proportionally if the font size changes.
A sidebar width is 320px. What is that in em at 16px base?
320 / 16 = 20em. A 20em sidebar adjusts with font size changes.
An icon is 48px. Express it in em for scalable SVG sizing.
48 / 16 = 3em. The icon will be 3x the current font size.
A margin of 12px between paragraphs needs to be in em.
12 / 16 = 0.75em. Proportional spacing that respects text size preferences.
A nested element has a parent at 20px font size. Convert 30px to em relative to this parent.
30 / 20 = 1.5em. Here the base is 20px, not 16px, because em is relative to the parent.

Quick Reference

Pixel (px)Em (em)
10.0625
20.125
30.1875
50.3125
100.625
150.9375
201.25
251.5625
503.125
754.6875
1006.25
25015.625
50031.25
1,00062.5

History of Pixel and Em

The "em" unit takes its name from traditional typography, where it originally referred to the width of the capital letter "M" in a given typeface. In modern CSS, it was redefined to equal the computed font size of the current element. The W3C adopted em as a CSS unit to enable relative sizing that adapts to user preferences. When CSS was first specified in 1996, em was already considered a best practice for accessible text sizing. The push for em and rem units accelerated with the rise of responsive web design in the 2010s, as fixed pixel sizing did not adapt well to the enormous range of screen sizes from watches to televisions.

Common Mistakes to Avoid

  • Forgetting that em compounds. If a parent is 1.5em and a child is also 1.5em, the child's computed size is 1.5 x 1.5 = 2.25 times the root font size. This compounding effect can cause unexpected sizing in deeply nested elements. Use rem instead of em to avoid this.
  • Always dividing by 16 regardless of context. Em is relative to the parent element's font size. If the parent is 20px, then 1em = 20px in that context, and converting 30px requires dividing by 20, not 16.
  • Using em for everything without considering rem. For font sizes and component-level spacing, rem (relative to root) is often more predictable than em (relative to parent). Use em intentionally when you want proportional scaling relative to the nearest text size.
  • Converting component spacing from px to em using the page body size instead of the component's local font size. If a card uses 18px text, a 24px padding target is 1.333em in that card, not 1.5em.
Ad Slot (auto)

Frequently Asked Questions

What is the difference between em and rem?
Em is relative to the parent element's font size. Rem is relative to the root (html) element's font size (usually 16px). Rem does not compound β€” 1.5rem is always 24px if the root is 16px, regardless of nesting depth. Em compounds, making it harder to predict in nested structures.
Why not just use pixels everywhere?
Pixels do not scale when users change their browser font size for accessibility. If you set all text and spacing in px, visually impaired users who increase their default font size will not see your layout adapt. Em and rem respect these preferences.
When should I use em vs. rem vs. px?
Use rem for font sizes and global spacing (predictable, accessible). Use em for component-internal spacing that should scale with the component's text size. Use px for borders, shadows, and elements that should not scale with font size.
Is 16px always the default base font size?
In all major browsers (Chrome, Firefox, Safari, Edge), the default root font size is 16px. However, users can change this in their browser settings, and some websites set a different root font size via CSS. Always check the actual computed value.
How many em is 24px at an 18px parent size?
Divide 24 by the local base of 18px: 24 / 18 = 1.333em. This is a good example of why em conversion depends on context rather than on the 16px browser default.
Quick Tip

Note: Em and rem assume a 16px base font size by default. If your project sets a different root font size (e.g., html { font-size: 62.5%; } for a 10px base), adjust all px-to-em calculations accordingly. The "62.5% trick" makes mental math easier: 1rem = 10px, 1.6rem = 16px, 2.4rem = 24px.

Sources & References