Guide
px vs rem in CSS: which to use and how to convert
When to use px, rem, or em in CSS, why rem is better for accessibility, and how the px ÷ root-size math works — with a live converter to follow along.
Designers hand off pixel values, but modern CSS is usually written in rem so the page respects
the user's font-size preference. This guide explains the difference between px, rem, and em,
when to use each, and how the conversion works. Use the converter above to turn any value as you
read.
The three units
- px — an absolute pixel.
16pxis always 16 pixels, regardless of any font settings. - rem — "root em". Relative to the root element's font size. With the default
16pxroot,1remis16pxand1.5remis24px. - em — relative to the current element's font size, which means it compounds when elements are nested inside one another.
How the conversion works
The math is simple division against the root font size:
rem = px ÷ root font size
px = rem × root font size
So with a 16px root, 24px is 24 ÷ 16 = 1.5rem, and 2rem is 2 × 16 = 32px. If your project
sets html { font-size: 10px } to make the math easier, change the root size field in the converter
and the results update.
Why rem is better for accessibility
When a user increases their browser's default font size — something many people rely on — elements
sized in rem scale up with it, because they are all measured against that root size. Elements
sized in px stay fixed and can break layouts or stay uncomfortably small. Sizing typography and
spacing in rem keeps your design usable at any base size.
A common pattern is to size almost everything in rem, and reserve px for things that genuinely
should not scale, such as 1px borders.
Try it
Enter a value above, pick its unit, and set your root font size to see it converted to px, rem, em, and pt at once — handy when translating a design's pixel values into a scalable stylesheet.