Pixels, rem and em
A CSS pixel (px) is a fixed unit. A rem is relative to the font size of the root element, the html tag, so 1rem is 16 px when the browser keeps its default size. An em is relative to the font size of the element itself, and for font-size to that of its parent.
Because em follows the parent, it compounds: a list set to 0.875em inside another list set to 0.875em ends up at about 77% of the base size. Rem always refers back to the root, which makes it easier to keep a type scale consistent across a site.
How to convert px to rem
Divide the pixel value by the root font size. To go back, multiply the rem value by the root font size. With the usual 16 px root, 24 px is 1.5rem and 14 px is 0.875rem.
Some projects set the root to 62.5%, which makes 1rem equal 10 px at the default size and turns the arithmetic into moving a decimal point. Enter 10 as the root font size to convert for those projects.
rem = px ÷ root font size px = rem × root font size 24 ÷ 16 = 1.5rem 1.5 × 16 = 24 px Root at 62.5% (10 px): 24 ÷ 10 = 2.4rem
Why rem respects the reader
Browsers let people choose a larger default font size in their settings. Text sized in rem or em grows with that choice; text sized in px stays the same, even though page zoom still enlarges both. Sizing type in rem keeps a design readable for people who need bigger text without any extra work.
For design teams the practical part is the handover: design files measure in pixels, the code uses rem. Agree on the root size once, and convert every font size and spacing value from the same number.
- Use rem for font sizes, and for spacing that should grow with the text
- Keep px for hairline borders and details that should not scale
- Set the root as a percentage (100% or 62.5%), not a fixed px value, so the reader’s setting still counts
- Round to values the type scale already uses instead of keeping long decimals