PX to EM Calculator
Convert pixels to em or rem, or em back to pixels, against any base font size — with the ready-to-paste CSS declaration.
How it works
px → em: em = px ÷ base · em → px: px = em × base · (rem uses the root element font size instead of the parent)
The em and rem units are multiples of a font size: 1em equals the current element's font size, and 1rem equals the root (html) font size — 16px in every browser by default. To turn a pixel measurement into em you divide by the base font size; to go back you multiply. rem is usually the safer choice because it always references the same root value, whereas em compounds when nested elements each set their own font size. Sizing in these relative units lets a whole layout scale when the user changes their default text size.
Worked example
A 24px heading against the default 16px base is 24 ÷ 16 = 1.5em (and 1.5rem when the root is 16px), written font-size: 1.5em;. Going the other way, 1.5em at a 16px base is 1.5 × 16 = 24px.
Sources: MDN — CSS values and units
Frequently asked questions
What is the difference between em and rem?
rem is always relative to the root font size (the html element), so it stays predictable. em is relative to the current element's own font size, which means it multiplies through nested elements — two levels of 1.2em is 1.44× the outer size. Use rem for consistent sizing and em when you deliberately want values to scale with a local font size.
Why is the default base font size 16 pixels?
Every major browser ships with a default document font size of 16px, so 1rem = 16px unless a stylesheet overrides html { font-size }. Building on that default is why "62.5% trick" stylesheets set the root to 10px to make 1rem = 10px for easy mental math.
Should I convert padding and margins to em too?
You can, but remember that em on properties other than font-size still references the element's font size, not its width. For spacing that should scale with text, em is handy; for spacing relative to the viewport, use vw/vh or percentages instead.
Related calculators
This calculator is for educational purposes. Double-check important results before acting on them.