iwantcoding.com
🔥 Daily 👥 Rooms 🏆 Top Log in Sign up

PX to EM Converter

CSS lets you size things in pixels (px), em, rem, and other units. em and rem scale with font size — useful for responsive typography.

The conversion rule

If the root font size is 16 px (the browser default), then 1rem = 16px. em is relative to the parent's font size rather than the root.

Quick conversion table (16 px base)

pxremem
8 px0.5 rem0.5 em
10 px0.625 rem0.625 em
12 px0.75 rem0.75 em
14 px0.875 rem0.875 em
16 px1 rem1 em
18 px1.125 rem1.125 em
20 px1.25 rem1.25 em
24 px1.5 rem1.5 em
32 px2 rem2 em
48 px3 rem3 em
64 px4 rem4 em

When to use which

UnitUse for
pxBorders, fine details that shouldn't scale.
remFont sizes, padding, margins — scales with the user's preferred font size.
emSpacing inside a component that should scale with its own font size.
Formula: rem value = px value ÷ root font size. With the default 16 px root, divide by 16.

Example

Example
<!DOCTYPE html>
<html>
<head>
    <title>PX to EM Converter</title>
</head>
<body>

<h1>PX to EM Converter</h1>
<p>This is a demo page for the "PX to EM Converter" lesson.</p>

</body>
</html>
Try it Yourself »

Exercise

At the default 16px root font-size, how many pixels is 1em?

1em = px

Test yourself

Q1. 1 em equals the element's…
Q2. 1 rem equals the…
Q3. At default 16px root, 24px =…

Discussion

Loading…