px vs rem vs em: Which CSS Unit Should You Use?
Web & SEO · Published October 8, 2026 · Updated October 24, 2026 · 3 min read
Written by Akinrinmade Michael
CSS gives you many units for sizes. In everyday work three of them matter most: px, rem and em. Picking the right one makes your design adapt to different screens and to people's own settings, and avoids a few classic surprises.
px: a fixed size
A CSS pixel is a fixed unit. 16px is 16px no matter what the user prefers. That makes it predictable, but it ignores the font size people choose in their browser. A reader who has raised their default text size because the standard one is too small to read gets no benefit from sizes written in pixels.
rem: relative to the page
rem stands for "root em". It's relative to the font size of the <html> element, which is 16px by default in browsers. So 1rem is 16px, 1.5rem is 24px and 0.75rem is 12px. If a visitor raises their default font size, everything sized in rem grows with it.
em: relative to the parent
em is relative to the font size of the element it's used on (or of its parent, for font-size itself). That's useful for components that should scale together, such as a button whose padding follows its text size. The catch is that nested elements multiply:
ul { font-size: 1.2em; } /* 1.2 * parent */
ul ul { font-size: 1.2em; } /* 1.2 * 1.2 = 1.44 * the original */A third level of nesting gives 1.73 times the original. That's why rem is the safer choice for font sizes, and em is better saved for spacing that should track its own text.
A conversion table
| px | rem (base 16) | Typical use |
|---|---|---|
| 12px | 0.75rem | Fine print |
| 14px | 0.875rem | Small text and labels |
| 16px | 1rem | Body text |
| 20px | 1.25rem | Lead paragraphs |
| 24px | 1.5rem | Subheadings |
| 32px | 2rem | Headings |
| 48px | 3rem | Large headings |
Converting
- px to rem: divide by the base size. With 16px,
24px / 16 = 1.5rem. - rem to px: multiply.
0.875rem x 16 = 14px. - Don't change the base to 62.5% to make the maths easier. It overrides what the user chose in their browser, and you have to restore body text sizes everywhere.
Which should you use?
- Font sizes and spacing:
rem, so they respect the user's settings. - Component-level spacing that follows the text:
em. - Borders, shadows and hairlines:
px, because they should stay thin. - Media queries:
emorrem, so breakpoints move when the user zooms or changes their font size. In media queries, browsers base both on the default size, not on your html rule.
Why it's an accessibility matter
Accessibility guidelines ask that text can be resized up to 200 percent without losing content or function. Sizes in rem make that work in the browser's text-only zoom, and a page built from pixels often can't. It's one of the cheapest accessibility fixes you can make: change the units, and nothing else about the design has to change.
Fluid sizes with clamp
For headings that grow with the screen, the clamp() function takes a minimum, a preferred value and a maximum, and rem works well for the limits:
h1 { font-size: clamp(1.75rem, 4vw + 1rem, 3rem); }The heading never gets smaller than 1.75rem or larger than 3rem, and scales in between.
Common mistakes
- Setting the html font size in pixels, which cancels the user's preference.
- Using em for every font size and watching nested elements balloon.
- Using unitless line heights wrongly. A plain number like
1.5is best for line-height, because it scales with the font. - Converting by eye. Use the tool and keep the base consistent.
Use the PX to REM Converter to convert any value and see a table of common sizes. Build gradients and shadows with the CSS Generator, shrink the finished file with the CSS Minifier, and check text colors with the Color Converter.
Related reading: sizes are half of a style sheet and colors are the other half, covered in how to pick colors from a photo.