CSS PX-EM Converter
Translating pixels to em/rem is one of the most-Googled CSS questions. Assuming the default root font-size: 16px, the maths is just division by 16.
The cheat sheet (16px base)
| px | rem | Typical use |
|---|---|---|
| 10 | 0.625 | Smallest captions |
| 12 | 0.75 | Footnotes, table cells |
| 14 | 0.875 | Secondary text |
| 16 | 1 | Body text (default) |
| 18 | 1.125 | Comfortable body on large screens |
| 20 | 1.25 | Lead paragraph |
| 24 | 1.5 | h4 |
| 28 | 1.75 | h3 |
| 32 | 2 | h2 |
| 40 | 2.5 | h1 |
| 56 | 3.5 | Hero heading |
The formula
Quick conversion
rem = px / root-font-size /* default root is 16px */ px = rem * root-font-size
The 62.5% trick
Many design systems set html { font-size: 62.5%; } so 1rem = 10px, making mental maths trivial (24px = 2.4rem).
CSS
html { font-size: 62.5%; } /* now 1rem == 10px */
body { font-size: 1.6rem; } /* restore 16px body */
Tip: Don't mix
em and rem randomly. Use rem for predictable, global sizing; em when you specifically want a value to scale with its element.Example
Example
<!DOCTYPE html>
<html>
<head>
<style>
body { font-family: Verdana, sans-serif; }
.box { background: #04AA6D; color: #fff; padding: 20px; border-radius: 6px; }
</style>
</head>
<body>
<h1>CSS PX-EM Converter</h1>
<div class="box">Edit the CSS on the left, then click Run »</div>
</body>
</html>
Try it Yourself »
Exercise
24px equals how many rem at the default 16px root?
Answer:
rem
24 ÷ 16.
Discussion
Loading…