Stockio

REM vs EM: Why Relative CSS Units Still Matter

Build resilient typography and spacing with rem and em, convert design specs accurately, and test layouts that respect browser font preferences and zoom.

By Marcus Bell

Front-End Engineer ·

On this page

A button that looks balanced at a 16px font size can become cramped when its label grows. A dashboard that fits your screen can overflow when someone increases their default text size. Relative units help solve both problems, but only when their reference sizes are intentional.

This guide turns pixel-based design measurements into a predictable sizing system. You will separate root-relative sizing from component-relative sizing, avoid compounding surprises, and test the result against real reading preferences rather than a single screenshot.

Start with the reference size, not the conversion

A conversion is only correct when its reference size is correct. With a 16px root, 24px equals 1.5rem. With a 20px root, the same 1.5rem resolves to 30px. That difference is useful: a user who requests larger default text should generally receive a larger interface, not a silently overridden preference.

Use the CSS Unit Converter (PX to REM) below to explore those relationships before updating styles. Enter your intended base size, convert a few representative measurements, and record the assumption beside your design tokens. The converter provides arithmetic; your stylesheet determines the actual reference.

Avoid treating relative units as an automatic accessibility guarantee. Content reflow and readable line lengths still depend on wrapping, container constraints, and overflow behavior. Start with body text, a button, and a card rather than converting every number in a repository. These three components expose most sizing mistakes quickly.

Choose rem for shared scales and em for local relationships

The root font size defines one rem throughout the document. This makes rem useful for typography scales, page gutters, and spacing tokens that should not depend on nesting. A 1.5rem gap remains consistent inside a large heading wrapper and a small caption wrapper.

An em has a more local relationship. For most properties, it refers to the element's computed font size. On the font-size property itself, em resolves against the inherited font size. That distinction explains why repeated 1.2em font sizes can compound across nested elements.

Use em when component proportions should follow their own text. A button with 0.6em vertical padding grows naturally when its font size changes. Use rem when multiple components must share an identical gap regardless of their labels. Neither unit is universally better; each expresses a different dependency.

The MDN length reference documents these relationships and other relative lengths. Be especially careful with inherited line-height: unitless values multiply by each descendant's own font size, while inherited fixed lengths can produce unexpectedly tight lines.

Keep the browser's starting point

Prefer leaving the root font size alone, or setting it to 100%. The familiar 62.5% shortcut makes arithmetic convenient but changes the starting scale. A converter removes that arithmetic burden without making 10px-equivalent body defaults part of your architecture.

Build a small, explicit token system

Create a shared scale before replacing measurements. Five spacing values and four text sizes are often enough for an initial migration. Preserve the existing visual design at its reference size, then check how the same relationships behave when that reference changes.

:root {
font-size: 100%;
--space-1: 0.25rem;
--space-2: 0.5rem;
--space-3: 1rem;
--space-4: 1.5rem;
--space-5: 2rem;
--text-body: 1rem;
--text-small: 0.875rem;
}

body {
margin: 0;
font-size: var(--text-body);
line-height: 1.5;
}

.card {
padding: var(--space-4);
border: 1px solid #cbd5e1;
border-radius: 0.75rem;
}

.button {
font: inherit;
padding: 0.6em 1em;
min-block-size: 2.75rem;
}

.button--large {
font-size: 1.25rem;
}

Here the button's padding follows its text, while its minimum height follows the document scale. The border stays in pixels because it expresses a fine visual edge, not a typographic relationship. CSS pixels still participate in page zoom; they are not physical device pixels.

Choose names that describe reusable roles rather than an accidental screenshot measurement. The design token workflow offers a useful next step for keeping those names consistent between design files and implementation. Resist adding a token for every isolated exception.

Combine flexible text with flexible containers

Relative text inside a rigid container can still break. Replace fixed heights on text-heavy cards with padding and minimum heights. Allow grid children to shrink, and let long identifiers wrap where their meaning permits. Flexible containers matter as much as the units inside them.

For fluid headings, combine a rem-based floor and ceiling with a viewport-sensitive middle value. The fluid typography guide explains how to calculate that interpolation rather than choosing arbitrary numbers.

.article {
inline-size: min(100% - 2rem, 68rem);
margin-inline: auto;
}

.article h1 {
font-size: clamp(2rem, 1.4rem + 2vw, 3.5rem);
line-height: 1.1;
overflow-wrap: anywhere;
}

.card__content {
min-inline-size: 0;
}

The heading retains relative bounds, but the viewport term can still affect how it responds to zoom. Test it rather than assuming any use of rem makes a fluid expression accessible. Avoid pure viewport-based body text, which can become smaller on narrow screens precisely when reading is hardest.

Percentage widths remain useful for available space, while character-based widths can help constrain prose. Unit selection should communicate the relationship you want: text scale, local proportions, available width, or a fine decorative detail.

Test font preferences and zoom separately

Browser page zoom and default font preferences are different test conditions. Page zoom generally enlarges CSS pixels and reduces the effective layout viewport. Changing the default font size changes the basis of relative text without necessarily producing the same layout behavior.

Run a short, repeatable test pass on a content page and an interactive screen. The WAI resize-text guidance explains the requirement to support text resizing without losing content or functionality. The separate reflow guidance helps assess narrow layouts.

  1. Increase the browser's default font size from 16px to 20px and reload.
  2. Zoom the page to 200% and inspect navigation, dialogs, and form errors.
  3. Test a 320 CSS pixel viewport for unintended horizontal scrolling.
  4. Replace short labels with longer translations and realistic account names.
  5. Navigate with the keyboard and verify that focus indicators remain visible.

Watch for clipped content, fixed-height controls, overlapping labels, and sticky headers that occupy most of the viewport. Record failures by component, not just by page, so one repair can fix multiple routes.

Before merging, revisit the unit conversion tool to check the handful of values that differ from your intended scale. Conversion mistakes are easy to fix; hidden sizing dependencies usually require a structural change.

Key takeaways

  • Use rem for shared scales so typography and spacing respond predictably to the document root.
  • Use em for local proportions, especially padding that should grow with component text.
  • Keep root preferences intact, and reserve pixels for details that do not need typographic scaling.
  • Combine relative units with wrapping, flexible containers, and sensible minimum sizes.
  • Test default font changes, page zoom, and narrow reflow as separate conditions.
  • Convert representative components first, then expand the system once their behavior is reliable.
Featured sponsor

Reach designers & developers at work

Put your product next to the tools people use every day. One sponsor per placement, no tracking pixels.

Become a sponsor

Keep reading

Related articles

More in HTML & CSS
HTML & CSS

CSS Logical Properties for RTL-Ready Layouts

Use logical margins, padding, borders, and sizing to support different writing directions without duplicated stylesheets or fragile left-and-right overrides.

Includes: PX to REMMarcus BellMarcus Bell
HTML & CSS

System Font Stack in CSS: Reliable Native Typography

Use system fonts intentionally across operating systems. Learn how native font stacks affect visual tone, metrics, weights, numerals, and text wrapping.

Includes: PX to REMMarcus BellMarcus Bell
HTML & CSS

Font Optical Sizing in CSS: Small Text and Headlines

Understand optical size in variable fonts and use font-optical-sizing safely. Compare body and display settings without confusing optical design with font size.

Includes: PX to REMJonah WeissJonah Weiss
HTML & CSS

Variable Fonts in CSS: Use Font Axes Without Breakage

Use variable font weight, width, and custom axes deliberately. Learn which CSS properties to prefer, how to inspect ranges, and how to test usable instances.

Includes: PX to REMMarcus BellMarcus Bell
Typography & Colour

10 Best Font Tools and Websites for Designers

Find ten useful places to discover, test, identify, and manage fonts for real design work. This guide compares free libraries, specimen tools, and pairing resources, with tips for licensing and responsive type.

Includes: PX to REMMateo FernándezMateo Fernández
Typography & Colour

15 Best Google Font Pairings for Websites

Find fifteen ready-to-test Google Fonts pairings for websites, from crisp product interfaces to editorial pages, with notes on hierarchy, tone, and the trade-offs to consider.

Includes: PX to REMNoor HaddadNoor Haddad