The formula and where the root size comes from
One rem equals the computed font size of the root <html> element. To convert, divide pixels by that size to get rem, or multiply rem by it to get pixels. The root box on this page defaults to 16, the usual browser default, and changing it redraws the quick-reference table straight away. Whichever of the px or rem boxes you edited last stays the source: change the root size after typing a px value and the rem box updates, and change it after typing a rem value and the px box updates. If you clear it or enter zero or less, the maths quietly falls back to 16. Results are rounded to three decimal places.
Worked example
At a 16px root, 24px is 24 / 16 = 1.5rem and 14px is 0.875rem. The same pixel values come out differently when the root changes, which is why the root box matters.
| px | rem at 16px root | rem at 10px root | rem at 18px root |
|---|---|---|---|
| 10px | 0.625 | 1 | 0.556 |
| 14px | 0.875 | 1.4 | 0.778 |
| 16px | 1 | 1.6 | 0.889 |
| 24px | 1.5 | 2.4 | 1.333 |
| 32px | 2 | 3.2 | 1.778 |
Pitfalls with rem
- The 62.5% trick. Some stylesheets set
html { font-size: 62.5%; }so that 1rem equals 10px on a default browser. If your project does this, enter 10 as the root here. It also shrinks any text you forget to size, so setbodyback to a readable size. - Setting the root in px. A rule like
html { font-size: 16px; }overrides the user's browser text-size preference, which defeats the main reason for using rem. Prefer leaving it unset or using a percentage. - Rounded values. 13px becomes 0.813rem, which renders as 13.008px at a 16px root. That difference is invisible, but if you need exact output keep more decimals in your own stylesheet.
- Media queries. In a media query, rem and em are measured against the browser's initial font size, not your own
htmlrule. A breakpoint of48remis 768px on a default browser regardless of what the stylesheet sets. - Browser zoom versus text size. Zooming the page scales everything, pixels included. Only the browser's default font-size setting separates rem from px, so test that setting rather than zoom.
Typical values to convert are font sizes, line heights, padding and margins; hairline borders and shadows usually stay in px. If you are converting other units, the unit converter covers general measurement, and the border radius generator produces the radius values you may want to express in rem.