Skip to content
OverCalculator
  1. Home
  2. Conversion
  3. Px to Em Converter
Conversion

Px to Em Converter

Convert CSS pixels to em units, or em back to pixels, with the base font size that defines one em in a specific typography context.

Published

Converted size
Ems
2 em
Pixels entered
32 px
Base font size
16 px
Relationship
1 em = 16 px

32 px divided by a 16 px base equals 2 em.

Direction
The CSS pixel value you want to express in em.
px
The font size that equals 1 em. Browsers commonly use 16 px by default.
px

Results update as you type.

Px to Em Converter

CSS pixels and em units solve different layout problems. Pixels give a fixed computed length in CSS. Ems scale from a font-size context, so they can make typography, padding, margins, and component dimensions grow with text. This converter translates between the two by using the base font size that represents 1 em. The default form follows a common browser starting point: 32 px at a 16 px base equals 2 em.

The base is the heart of the calculation. A designer may write a mockup with a 16 px body size, a product card may set its own 14 px font size, and a large button may use a 20 px label. In each case, one em is different. This page focuses on CSS and responsive design, while the pixels to inches converter uses PPI for physical output, the length converter handles fixed real-world units, and the measurement converter collects broader everyday unit conversions.

What an em means in CSS

An em is a relative length unit. In font-size declarations, em values are relative to the parent element’s computed font size. In many other properties, such as padding or margin, em values are relative to the element’s own computed font size. That distinction is why em units can feel powerful and surprising at the same time. They let a component breathe with its text, but nested font-size changes can compound if you are not watching the calculated values.

Pixels are also CSS units, not necessarily physical screen pixels. A CSS pixel is a reference unit defined by CSS specifications and mapped by the browser to the device through zoom and scaling. For typography work, however, the px-to-em conversion is normally about computed CSS pixels. If the computed base font size is 16 px, then 1 em is 16 px in that context. If the computed base is 18 px, then 1 em is 18 px there.

Rem units are related but not identical. A rem is root-relative, so it looks to the root element rather than to each local parent. Use rem when you want a consistent site-wide scale. Use em when a component’s spacing should follow its own text size. A button with horizontal padding of 1.25 em, for example, will expand naturally when the button’s font size is increased for a hero section.

Formula used by the calculator

The form has two directions. In px-to-em mode, the calculation checks that the base font size is positive and the pixel value is not negative, then divides:

em=pxbase font size in px\text{em} = \frac{\text{px}}{\text{base font size in px}}

In em-to-px mode, it checks the em value and multiplies:

px=em×base font size in px\text{px} = \text{em} \times \text{base font size in px}

The displayed result uses up to four decimals. Four decimals are usually enough for design tokens and CSS custom properties without creating noisy values. You can still round by design intent afterward; for example, 0.875 em is usually more readable than 0.8749 em if the difference is visually irrelevant.

Worked example matching the default form

The default direction is px to em. The pixel input is 32 px and the base font size is 16 px. The calculator divides:

em=3216=2\text{em} = \frac{32}{16} = 2

The primary answer is 2 em. The detail rows show 32 px as the entered pixel value, 16 px as the base font size, and the relationship 1 em = 16 px. The note says that 32 px divided by a 16 px base equals 2 em, matching the calculation exactly.

Switch to em-to-px mode and leave the default 2 em with the same 16 px base. The calculator multiplies:

px=2×16=32\text{px} = 2 \times 16 = 32

The primary answer becomes 32 px. This reverse check is a useful way to verify that your design token, CSS variable, or component spacing still maps to the intended pixel value.

Reference table

Pixel valueBase font sizeEm valueCommon use
4 px16 px0.25 emTiny gap tied to text size
8 px16 px0.5 emCompact inline spacing
12 px16 px0.75 emSmall text or padding
14 px16 px0.875 emSecondary text size
16 px16 px1 emBase text size
20 px16 px1.25 emLarger label or button text
24 px16 px1.5 emHeading or generous spacing
32 px16 px2 emDefault calculator example
30 px20 px1.5 emSame ratio in a larger context

Do not copy the table blindly into every project. It assumes the base shown in the middle column. If a card sets font-size to 14 px, then a 21 px spacing is 1.5 em inside that card. If a modal sets font-size to 18 px, the same 1.5 em spacing becomes 27 px.

Where em conversions help

Em units are strongest when the measurement should respond to text. Button padding, icon gaps beside labels, input heights, chip spacing, and callout boxes often feel more consistent when they scale with the component’s font size. If a user increases text size for accessibility, em-based spacing can preserve the visual proportions around the text instead of leaving cramped fixed-pixel boxes.

They are also useful in design systems. A token such as 0.75 em can mean “three quarters of the local text size” across many components. That is different from a token such as 12 px, which means one fixed CSS length everywhere. Neither is universally better; the right choice depends on whether the spacing should be local and proportional or global and fixed.

Pitfalls to avoid

  • Assuming the base is always 16 px. It is common, not guaranteed.
  • Converting font size to em inside nested elements without checking compounding. A child set to 1.25 em inside a parent already set to 1.25 em grows by both factors.
  • Treating em and rem as interchangeable. Rem ignores local component font-size changes; em follows them.
  • Rounding every value to one decimal. A value such as 0.875 em is common and meaningful in typography.
  • Converting only text while leaving related padding in fixed pixels. The text can grow while the box around it does not.

Accuracy and limits

The calculator keeps the defined or cited relationship through the calculation and rounds only the displayed result. A converted number does not become more precise than the source measurement. Keep additional digits for chained calculations, then round to the precision justified by the original value; also preserve any reference basis or notation convention named with the input.

Sources

Frequently asked questions

What base font size should I enter for px to em?
Enter the font size that defines one em in the context you are converting. Browser defaults are commonly 16 px, and the calculator uses 16 px by default, but a component, parent element, or design system can change the relevant base. Use the computed CSS value when precision matters.
How do I convert pixels to em units?
Divide the pixel value by the base font size in pixels. With the default base of 16 px, 32 px divided by 16 px equals 2 em. If the base is 20 px, that same 32 px becomes 1.6 em, so the base is not optional.
How do I convert em back to pixels?
Multiply the em value by the base font size. For example, 1.5 em at a 16 px base is 24 px, while 1.5 em at a 20 px base is 30 px. The same em number produces different pixel sizes in different text contexts.

Related calculators

Px to Em Converter updated at