PX vs REM vs EM: Which CSS Unit to Use for Font Sizes, Spacing and Media Queries
CSS offers several length units, and three come up constantly in everyday styling: px, rem and em. They can all produce the same size on screen, but they behave very differently when users change their browser settings or when elements are nested. Choosing the right one makes layouts more accessible and easier to maintain.
The three units
px (pixels) is an absolute CSS unit. One CSS pixel is defined as 1/96 of an inch at a typical viewing distance; on high-density screens, one CSS pixel covers several physical pixels.
rem (root em) is relative to the font size of the root element (html). By default, browsers set that to 16px, so 1rem = 16px, 1.5rem = 24px.
em is relative to the font size of the current element (or, for the font-size property itself, the parent’s font size). It compounds when nested.
| Unit | Relative to | Changes with user’s default font size? | Compounds when nested? |
|---|---|---|---|
| px | Nothing (absolute) | No | No |
| rem | Root font size | Yes | No |
| em | Current/parent font size | Yes | Yes |
Why rem matters for accessibility
Browsers let users set a default font size (in Chrome: Settings → Appearance → Font size). People with low vision often increase it from the default “Medium” (16px) to 20px or more. If your font sizes are in rem, they scale with that setting. If they’re in px, they ignore it.
This is different from zoom, which scales everything, including px values. Zoom works with any unit. The default font size setting only affects relative units. Respecting both is part of good accessibility practice, and WCAG 1.4.4 requires that text can be resized to 200% without loss of content or function.
The em compounding problem
Because em is relative to the parent, nested elements multiply:
.list { font-size: 1.2em; }A list inside a list is 1.2 × 1.2 = 1.44 times the base size; three levels deep, 1.73 times. That’s rarely intended, and it’s why rem became the default for font sizes.
When em is the right choice
em’s relativity is useful when something should scale with the element’s own text:
- Padding on buttons:
padding: 0.5em 1emmeans a larger button text automatically gets proportionally larger padding. - Icon sizes next to text:
width: 1em; height: 1emmakes an icon match the text it sits beside. - Letter spacing:
letter-spacing: 0.05emscales with font size. - Media queries: browsers evaluate em and rem in media queries against the initial font size, and em/rem breakpoints respond consistently when users change their default font size.
Practical rules
| What you’re styling | Recommended unit | Why |
|---|---|---|
| Font sizes | rem | Respects user settings, no compounding |
| Spacing (margins, padding, gaps) | rem (or px on a strict 8pt grid) | Keeps proportion with text |
| Component-internal padding | em | Scales with the component’s text size |
| Borders and hairlines | px | A 1px border should stay 1px |
| Box shadows | px | Visual effects don’t need to scale |
| Media query breakpoints | em or rem | Responds to font size settings |
| Line height | Unitless (1.5) | Scales with each element’s font size |
| Max-width for text | ch or rem | Ties line length to text size |
The 62.5% trick and why to avoid it
A popular old technique sets html { font-size: 62.5%; } so that 1rem equals 10px, making conversions easy (1.6rem = 16px). It has downsides:
- Every component must set its own font size, or text renders at 10px by default.
- Third-party components that assume 1rem = 16px end up too small.
- It confuses anyone joining the project.
Converting px to rem is just division by 16. A px to rem converter or a CSS preprocessor function handles it, so the trick isn’t necessary.
Converting px to rem
rem = px ÷ root font size
| px | rem (base 16) |
|---|---|
| 12 | 0.75 |
| 14 | 0.875 |
| 16 | 1 |
| 18 | 1.125 |
| 20 | 1.25 |
| 24 | 1.5 |
| 32 | 2 |
| 48 | 3 |
Designers usually work in px in Figma; developers convert to rem when implementing. Keeping the design scale on round numbers (multiples of 4 or 8) gives clean rem values.
Other units worth knowing
- % is relative to the parent (for widths) or the parent’s font size (for font-size).
- vw / vh are relative to the viewport; use them inside
clamp()for fluid sizes, never alone for text. See our viewport units guide. - ch is the width of the “0” character;
max-width: 65chis a quick way to limit line length. - pt (points) belongs to print. 12pt = 16px at the CSS standard of 96 pixels per inch; our design units guide covers print units.