PX vs REM: Which CSS Unit Should You Use?

This question comes up in almost every CSS code review: should this value be in px or rem? Both are valid, and the right answer depends on what the value is actually doing, not on a blanket rule.

How Each One Behaves

px is an absolute unit โ€” 16px is 16px no matter what. rem is relative to the root font size, which defaults to 16px in every major browser but can be changed by the user, or by your own CSS (some teams set html { font-size: 62.5%; } to make 1rem = 10px for easier mental math).

That one difference โ€” fixed vs. relative to a setting the user can control โ€” is what drives every recommendation below.

PX vs REM Side by Side

pxrem
Type of unitAbsoluteRelative to the root font size
Default size of 1 unit1 CSS pixel16px
Scales with browser zoomYesYes
Scales with the user's default font-size settingNoYes
Affected by nestingNoNo
Easy to read at a glanceVeryNeeds a quick division by 16

Notice that both units scale with browser zoom. The difference only appears when someone changes their default font size in the browser settings, which is a separate control from zoom. Our article on how browser zoom affects rem and em explains why the two settings behave differently.

A Worked Example: A User With a 20px Default

Imagine a reader who has set their browser's default font size to 20px (the "Large" option in some browsers) because 16px text is hard for them to read. Here is what happens to the same card written two ways:

PropertyWritten in pxRenders asWritten in remRenders as
Body text16px16px1rem20px
Heading24px24px1.5rem30px
Card padding24px24px1.5rem30px
Border1px1px1px1px

The px version ignores the reader's preference completely. The rem version grows by 25% across text and spacing, while the border โ€” correctly left in px โ€” stays a crisp 1px line.

Where PX Still Makes Sense

Where REM Wins

A Simple Decision Rule

Ask: "should this get bigger if the user increases their font size?" If yes โ€” font-size, padding, margin, line-height โ€” use rem. If no โ€” borders, shadows, fixed-size icons, breakpoints โ€” use px. Most real projects end up using both side by side, and that's the correct outcome, not a compromise.

Quick Reference: Which Unit for Which Property

PropertyRecommendedWhy
font-sizeremRespects the user's font-size setting
padding, margin, gapremWhitespace grows in step with text
line-heightUnitless (e.g. 1.5)Recalculated for each element's own size
max-width of text blocksrem or chKeeps line length readable when text grows
border-widthpxThin lines should stay thin
box-shadow, outline-offsetpxPurely visual, not tied to reading
border-radiusEitherpx for a fixed look, rem if it should match padding
Media query breakpointspx or emPick one convention project-wide

Should You Use the 62.5% Trick?

Setting html { font-size: 62.5%; } makes 1rem equal 10px at the default, so 18px becomes 1.8rem without mental division. It still respects user settings because it is a percentage. The trade-offs: any third-party component that assumes 1rem = 16px will render at 62.5% of its intended size, and you must remember to set body { font-size: 1.6rem; }. Many teams now skip the trick and rely on a converter or a small preprocessor function instead:

// Sass helper: rem(24) โ†’ 1.5rem
@use "sass:math";
@function rem($px, $base: 16) {
  @return math.div($px, $base) * 1rem;
}

.title { font-size: rem(28); }   // 1.75rem

Migrating an Existing PX Codebase

  1. Remove any px font size on html. Replace html { font-size: 16px; } with 100% or delete it, otherwise rem values will not respond to user settings either.
  2. Convert font sizes first. They have the biggest accessibility impact. Divide each value by 16 โ€” 14px becomes 0.875rem, 18px becomes 1.125rem. Our step-by-step guide on how to convert PX to REM has a full table.
  3. Convert spacing next: padding, margin and gap values that sit around text.
  4. Leave borders, shadows and icon sizes in px.
  5. Test with a larger default font size. Set your browser to 20px or 24px and look for clipped buttons, overflowing navigation and fixed heights that no longer fit.

Common Mistakes

Frequently Asked Questions

Does using rem hurt performance?

No. The browser resolves rem to pixels during style calculation, and there is no meaningful performance difference between the two units.

Is px bad for accessibility?

Not in itself. Px is fine for borders, shadows and decorative details. The accessibility problem is specifically px font sizes and text-related spacing, because they ignore the user's default font-size preference.

Why do some design tools only show px?

Design tools work on a fixed canvas, so px is a natural unit for them. Treat the px values as the design at a 16px root and convert them when you write CSS.

Can I use rem for media queries?

You can. Rem and em in media queries both refer to the browser's initial font size, so 48rem is 768px at the default. They do not follow a font size you set on html in your stylesheet.

Try It Yourself

Switching between the two by hand for a specific value? Our PX to REM converter does the conversion instantly, using either the default 16px root or a custom base you set, and the REM to PX converter works the other way.