How to convert px to rem
Divide the pixels by the root font size (the font size of the html element). To go back, multiply rem by the root font size. em works the same way, but against the font size of the element’s parent instead of the root.
Here it is with your numbers:
- 24 ÷ 16 = 1.5rem.
- As a percentage of the base, that is 1.5 × 100: 150%.
- In points (72 to the inch, 96 px to the inch): 24 × 0.75 is 18pt.
It means you can write 24px as 1.5rem, and it grows if the reader makes their text bigger.
Source W3C · CSS Values and Units Level 4, §6.1.1 Font-relative lengths (em, rem) ↗W3C · CSS Values and Units Level 4, §6.2 Absolute lengths ↗
PX to REM chart
At your root font size:
| Pixels | Rem |
|---|---|
| 8px | 0.5rem |
| 10px | 0.625rem |
| 12px | 0.75rem |
| 14px | 0.875rem |
| 16px | 1rem |
| 18px | 1.125rem |
| 20px | 1.25rem |
| 24px | 1.5rem |
| 28px | 1.75rem |
| 32px | 2rem |
| 36px | 2.25rem |
| 40px | 2.5rem |
| 48px | 3rem |
| 64px | 4rem |
rem or em?
- rem (root em) is always measured against the root font size, so 1.5rem is the same size everywhere on the page.
- em is measured against the font size of the element itself, which it inherits from its parent, so ems inside ems multiply: 1.5em inside a 1.5em box is 2.25 times the base.
- Both grow when the reader makes their browser’s text bigger; pixels set in CSS don’t.
FAQs
How many px is 1 rem?
1rem is the root element’s font size. With a 16px base, 1rem is 16px; with a 20px base it is 20px.
Source W3C · CSS Values and Units Level 4, §6.1.1 Font-relative lengths (em, rem) ↗
What is 1 px in rem?
At a 16px base, 1px is 0.0625rem (1 ÷ 16).
How to change px to rem?
Divide the pixels by the root font size. 24px ÷ 16 is 1.5rem.
Is 1 rem equal to 16px?
Only when the root font size is 16px. rem follows the root font size, so if the site sets html to 20px, or the reader turns up their browser’s text size, 1rem grows with it. That is why rem is used for text.
Sources
- W3C: CSS Values and Units Level 4, §6.1.1 Font-relative lengths (em, rem)
- W3C: CSS Values and Units Level 4, §6.2 Absolute lengths