HTML ReferencesLesson #87
PX to EM Converter
The tool below allows you to work out the em sizes from pixels (or vice versa).
The tool below allows you to work out the em sizes from pixels (or vice versa).
- Set a default pixel size for body (usually 16px)
- Then, convert a pixel value to em, based on the default pixel size
- Or, convert an em value to pixels, based on the default pixel size
Set a default pixel size:
px
Convert PX to EM: px
Convert EM to PX: em
Convert
Result:
Body Font Size
In the table below, select a body font size in pixels (px) to display a complete "px to em and percent" conversion table.
Tip: The default font size in browser is 16px.
What is the difference between PX, EM and Percent?
Pixel is a static measurement, while percent and EM are relative measurements. The size of an EM or percent depends on its parent. If the text size of body is 16 pixels, then 150% or 1.5 EM will be 24 pixels (1.5 * 16). Look at CSS Units for more measurement units.
Interactive Code Examples
PX to EM Converter Example
htmlLive code example for PX to EM Converter. Click Try it Yourself to test.
<!DOCTYPE html>
<html>
<head>
<style>
body {
font-family: system-ui, -apple-system, sans-serif;
padding: 24px;
background: #f8fafc;
color: #0f172a;
}
.demo-card {
background: #ffffff;
padding: 24px;
border-radius: 16px;
border: 1px solid #e0e7ff;
box-shadow: 0 10px 25px -5px rgba(79, 70, 229, 0.08);
max-width: 540px;
}
h2 { color: #4f46e5; margin-top: 0; font-size: 22px; }
p { color: #64748b; line-height: 1.6; }
.btn {
display: inline-flex;
align-items: center;
gap: 8px;
background: #4f46e5;
color: #ffffff;
border: none;
padding: 10px 20px;
border-radius: 9999px;
font-weight: 700;
font-size: 13px;
cursor: pointer;
box-shadow: 0 4px 12px rgba(79, 70, 229, 0.25);
}
.btn:hover { background: #4338ca; }
</style>
</head>
<body>
<div class="demo-card">
<h2>PX to EM Converter</h2>
<p>This is a live runnable interactive demonstration for <strong>PX to EM Converter</strong>.</p>
<button class="btn" onclick="alert('Testing PX to EM Converter!')">
<span>Interactive Action</span> →
</button>
</div>
</body>
</html>