lucky.graphics

guides

PX vs REM vs EM: How to Choose CSS Units Without Breaking Accessibility

Pixels, ems, and rems explained with worked conversions: which unit for font size, spacing, and breakpoints, why the root size is a user setting, and how this maps to WCAG resize requirements.

Published
October 2, 2026
Updated
October 28, 2026
Topic
guides
Reading time
22 min
Review
Reviewed against the primary source

PX vs REM vs EM: How to Choose CSS Units Without Breaking Accessibility

Set font sizes in rem, spacing inside components in em, hairline borders in px, and media queries in em. That split lets text follow the reader's browser font setting, keeps components in proportion, and moves layouts to one column when a reader's larger text needs it. A stylesheet carries a units strategy even when nobody chose one, and the wrong one makes a site fight the browser of the people who most need larger text.

This guide explains the three units designers actually choose between, px, em, and rem, with worked conversions you can check against the px-to-rem converter. It covers which unit to use for type, spacing, components, and media queries, the accessibility rule the choice hangs on, and the handful of mistakes that break zoom and user font settings on otherwise well-made sites.

Which Unit for Which Job

  • Font sizes: set them in rem. One rem equals the root element's font size, which the reader's browser settings control, so your sizes scale with their preference.
  • Spacing inside a component: em is the specialist. It scales with the component's own text size, so a button's padding grows when its label does.
  • Borders, hairlines, and pixel-exact nudges: px is fine. A 1px border does not need to respect anyone's font settings.
  • Media queries: em (or rem, which browsers treat identically there). The breakpoint then responds to the reader's font size as well as the window width.

Everything below is why, plus the arithmetic.

What a Pixel Actually Is in CSS

A CSS pixel is not a screen pixel. MDN's CSS length reference defines 1px as 1/96 of an inch and says that on printers and high-resolution screens "one CSS pixel implies multiple device pixels". Its own example is a screen with a devicePixelRatio of 3, where one CSS pixel covers three device pixels in each direction. That mapping is why a 16px heading looks about the same size on a laptop and on a dense phone screen.

The practical consequence: px in CSS already adapts to the device. What it does not adapt to is the reader. Set font-size: 16px on the html element and you have told every visitor that their browser's text-size preference no longer applies to your page. MDN's note on absolute lengths makes the same point from the other side: many users raise their default font size, absolute lengths "do not scale according to user settings", and relative lengths such as em or rem are preferred for font-size. If a size arrives in points from a print spec, the pt to px conversion table gives the exact pixel and rem values: 12pt is 16px, or 1rem at the default root.

The fix is structural: do not set the root font size in px. Leave it unset and the browser default flows through (MDN calls 16px "a common browser default" and adds that user preferences may change it), or set it as a percentage (100 percent, or a deliberate scale), which multiplies the user's setting instead of replacing it. Your rems then convert at whatever root size the reader actually has.

REM: Relative to the Root

A rem ("root em") always refers to the font size of the html element, wherever it is used in the document. Set the root at its untouched default and the conversions at default settings are simple multiples of 16px:

Design value (at default root)In rem
12px0.75rem
14px0.875rem
16px1rem
18px1.125rem
20px1.25rem
24px1.5rem
32px2rem
48px3rem

The right mental model is "desired size divided by root size," and the fastest way to sanity-check a conversion is the px-to-rem converter, which also handles the case where your project sets a different root size. Two properties make rem the right unit for type across a whole site. First, predictability: unlike em, a rem never compounds, so 1.25rem is the same size in the footer as in the hero. Second, respect: when a reader raises their browser's default font size, every rem on your page rises proportionally, which is exactly what they asked their browser to do.

The same table serves spacing. Page-level margins, paddings between sections, and gaps in layout grids take rem for the same reason type does, so the whole page breathes at the reader's scale:

Spacing value (at default root)In rem
4px0.25rem
8px0.5rem
16px1rem
24px1.5rem
32px2rem
48px3rem
64px4rem

Pick steps on a consistent rhythm (powers of two and simple halves keep a system legible to the next person), name them as tokens, and never type a raw spacing number anywhere again.

The well-known 62.5 percent trick, setting the root to 10px at default settings so 1.6rem reads as 16px, buys easier mental arithmetic. It still respects user settings, because it is a percentage of the user's default. The cost is elsewhere: a component library pasted into the project assumes 1rem is the reader's default size, so its text renders at 62.5 percent of what its authors drew, and a developer who inherits the file has to learn the convention before any number makes sense. Plain conversions and a converter at hand avoid both problems.

EM: Relative to Context

An em refers to a font size that depends on where the em is used. In the font-size property itself, 1em means the parent element's computed font size. In every other property, padding, margin, width, 1em means the element's own computed font size. That dual meaning is the source of both em's power and its one real hazard.

The power: component-relative spacing. A button with font-size: 1rem and padding: 0.6em 1.2em keeps its internal proportions at every size; grow the label and the padding grows with it. Alerts, badges, form inputs, and cards all benefit from spacing that tracks their own type rather than the root.

The hazard is compounding. Nested elements that each set font-size in em multiply: a 1.2em list inside a 1.2em section inside 1.2em body copy renders its text at 1.728 times the root size. Nothing warns you; the text is just quietly larger than the spec said. The discipline that avoids it is simple: font-size in rem, spacing in em. Then compounding can never happen, because em used for spacing refers to a font size that was itself set in rem.

Percent in font-size behaves like em (150 percent equals 1.5em): MDN defines a font-size percentage as "relative to the parent element's font size", so it compounds the same way. It is the right choice in exactly one common place: the root element, where 100 percent defers to the reader.

The Accessibility Rule Behind All of This

WCAG 2.1 Success Criterion 1.4.4, Resize Text (Level AA), reads: "Except for captions and images of text, text can be resized without assistive technology up to 200 percent without loss of content or functionality." The W3C's Understanding document for the criterion adds the two sentences that matter for unit choices. "The scaling of content is primarily a user agent responsibility." And: "The author's responsibility is to create web content that does not prevent the user agent from scaling the content effectively." It lists browser zoom (technique G142) and on-page controls that change the size of all text (G178) among the ways to meet it.

Units are how a page defeats scaling by accident. Text set in px inside a fixed-height container overflows or clips when the text doubles but the box does not, which is what Firefox's Zoom Text Only mode does at 200 percent; text set in rem clips the same way in that box when the reader doubles the default font size. Text set in rem on an untouched root, in containers that grow, scales the way the reader asked. The WCAG compliance guide covers the full checklist this criterion belongs to; the unit rules here are the piece that lives in your stylesheet.

Breakpoints belong to this story too. A media query written in em or rem is evaluated against the reader's root font size, so when a user raises their default text size, your "narrow layout" breakpoints arrive earlier, giving larger text the narrower, more readable measure. A breakpoint in px responds only to the window. That is the case for writing breakpoints in em: 48em at default settings is 768px, and it becomes a threshold that adapts to the reader rather than a magic number. The typography scale system guide shows how a rem-based scale and em breakpoints work together across a full design system.

Zoom and Text Size Are Two Different Settings

Most arguments about px and rem go wrong because they treat "the user made the text bigger" as one action. Most browsers offer two, and Firefox adds a third, Zoom Text Only, which in Mozilla's words makes the zoom controls "only change the size of text; not images". Units respond to each differently.

Page zoom (Ctrl or Cmd and plus) scales everything, pixels included. At 200 percent zoom a CSS pixel covers twice as many device pixels, so a 1280-pixel-wide window now reports a layout width of 640 CSS pixels. Text set in px, rem or em all doubles, and both breakpoints in the table below, the px one and the em one, see the narrower 640-pixel width. For zoom, the unit choice barely matters.

The default font size setting in the browser's appearance preferences changes only the initial font size, the value 1rem resolves to when the root is left alone. Here the units split. Media Queries Level 4 states that relative length units in media queries are based on the initial value, and that "the em unit is relative to the initial value of font-size, defined by the user agent or the user's preferences". So an em breakpoint moves with this setting and a px breakpoint does not.

The table works one window through both settings. Inputs: a 1280-pixel-wide window, body text at 1rem or at 16px, and a two-column layout that switches at 48em or at 768px.

What the reader changedText set in pxText set in rem768px breakpoint48em breakpoint
Nothing (16px default, 100% zoom)16px16pxTwo columns (1280 is above 768)Two columns (48 × 16 = 768)
Zoom to 200%32px on screen32px on screenOne column (640 CSS px is below 768)One column (640 is below 768)
Default font size set to 24px16px, unchanged24pxTwo columns, text squeezed at 1.5 times the size the layout was drawn forSwitches at 48 × 24 = 1152, still two columns in a 1280 window
Default font size set to 32px16px, unchanged32pxTwo columns, with 32px text crammed into eachOne column: 48 × 32 = 1536 is wider than the window
Where a 48em breakpoint lands as the reader's default font size changesLine chart. A 48em breakpoint rises in step with the reader's default font size: 576px at 12px, 768px at 16px, 960px at 20px, 1152px at 24px, 1344px at 28px and 1536px at 32px. A 768px breakpoint stays flat at 768 whatever the setting.40080012001600121620242832Reader's default font size (px)Window width where the layout switches (CSS px)48em at 12px default: 576px48em at 16px default: 768px48em at 20px default: 960px48em at 24px default: 1152px48em at 28px default: 1344px48em at 32px default: 1536px48em768px
Where a 48em breakpoint lands as the reader's default font size changesBreakpoint = 48 x the reader's default font size, because em in media queries resolves against the initial font size. The px breakpoint ignores the setting.Source: Media Queries Level 4, section 1.3 (W3C, February 19, 2026), checked October 28, 2026; values are our arithmetic.
Show the data as a table
Reader's default font size48em breakpoint768px breakpoint
12px576px768px
16px768px768px
20px960px768px
24px1152px768px
28px1344px768px
32px1536px768px

Two consequences follow. A px font size ignores the second setting completely, which is the reader-hostile behaviour this guide's first section warns about: someone who set 24px gets 16px anyway. And a px breakpoint with rem text produces the worst pairing in the last row, text at double size forced into columns sized for normal text, which is exactly where words start overflowing their cards. The em breakpoint is what gives that reader one comfortable column.

Zoom also enlarges images and layout chrome, which a reader who only wants bigger text may not want, so some readers use the font size setting instead. A site tested only with zoom passes for them by luck, so test both: zoom to 200 percent, then reset zoom and raise the default font size in the browser settings to its largest step.

A Worked Example: One Component, All Three Units

Consider a notification banner, starting from a spec written in pixels: 18px headline, 16px body, 16px padding, 24px vertical margin between banners, 1px border, on a root font size of 16px.

Converted sensibly:

  • Headline font-size: 1.125rem (18 divided by 16). It will scale with the reader's root setting.
  • Body font-size: 1rem. Paragraph spacing in rem, 1rem, keeps the vertical rhythm predictable across the page.
  • Padding: 1em. It tracks the banner's own text; if a compact variant drops the body to 0.875rem, the padding tightens by itself.
  • Margin between banners: 1.5rem. Page-level rhythm belongs to the root scale, not to one component's type.
  • Border: 1px. A hairline's job is to be a hairline at every setting.

Check any of the conversions instantly in the px-to-rem converter by entering the pixel value and your root size. The habit worth building is not memorizing the table; it is never writing a font-size the reader cannot override.

Running the 200 Percent Test on a Real Component

WCAG 1.4.4 asks that text can be resized to 200 percent without losing content or function. Here is that test worked on a pricing card, with the arithmetic shown, because the failure is easier to prevent once you have seen where it comes from.

Inputs. A card 320 pixels wide with 16 pixels of padding on each side, so 288 pixels for text. A heading of 20px on one line, three lines of 16px body text with a line height of 1.5, a 44-pixel button, and 12 pixels of gap between each of the three parts. Total content height: 20 × 1.5 for the heading (30), 3 × 24 for the body (72), the button (44) and two gaps (24) comes to 170 pixels, plus 32 of vertical padding, 202 pixels. The designer, measuring the mockup, fixed the card at height: 210px.

At 200 percent text size. Every text value doubles. The heading becomes 60 pixels of line box. The body text is now 32px in the same 288-pixel width, so a line holds roughly half as many characters, and three lines rewrap into about six: 6 × 48 = 288 pixels. If the button label is text in rem, the button grows too, to about 88 pixels. Content height: 60 + 288 + 88 + 24 = 460 pixels, plus padding, 492. The card is still 210 pixels high. With overflow hidden, more than half of the content, including the button, is cut off, which is a WCAG 1.4.4 failure for loss of both content and function. With overflow visible, the text spills over the next card instead, which fails the same criterion by making content unreadable.

The fix is not a different unit for the text, which is already right. It is removing the fixed height: min-height: 13.125rem (210 ÷ 16) keeps the mockup's look at default settings and lets the card grow to 492 pixels when it must. Gaps and padding in rem, or in em inside the card, then grow in proportion so the doubled text does not touch the card edges.

How to run it yourself. Raise the browser's default font size to 32px (or use Firefox's Zoom Text Only at 200 percent) and walk every template; then reset and test page zoom at 200 percent as well, because each setting exposes different failures. Look for three things: clipped text or controls (fixed heights, overflow hidden), overlapping text (absolute positioning, negative margins), and controls pushed off-screen horizontally (fixed widths in px). Anything you find is usually one declaration in a base style, which is why the test pays off early.

Breakpoints, Converted

The classic responsive widths, expressed the way your media queries should be once the root does the talking. Values assume the untouched 16px default; a reader at 20px shifts every threshold wider by the same proportion, which is precisely the behavior you want.

Window width (at default root)Media query
480px30em
640px40em
768px48em
1024px64em
1280px80em
1536px96em

Tokens and Scales: Where the Units Live in a Design System

A team usually meets this question at the design-token layer, where spacing and type decisions get names. Keep the unit rules in the token values themselves: type tokens in rem (t-body 1rem, t-h2 1.5rem, t-display 3rem), space tokens in rem for page rhythm (space-4 1rem, space-8 2rem), and let components translate space into em with their own local font size when the padding should breathe with the label. The token names then stay stable forever while the units quietly route each value to the right behavior.

Two scale habits pair well with this. Set line-height as a unitless multiplier (1.5, not 1.5em or 24px). MDN's line-height reference explains why: the used value is the number multiplied by the element's own font size, which makes it, in MDN's words, "the preferred way to set line-height and avoid unexpected results due to inheritance". And name breakpoints after what the layout does rather than a device: mq-stack 30em, mq-two-col 48em, mq-wide 80em. Devices change yearly; layout intentions do not.

Two Production Bugs This Prevents

  1. The fixed-height clip. A card given an exact pixel height swallows rem-sized text whole at 200 percent resize, the precise failure the resize criterion describes. Minimum heights, or none at all, let the box grow with its content.
  2. The compounded sidebar. A navigation component that sets its font size in em, nested inside two ancestors that did the same, drifts from every mockup and gets "fixed" with a hard-coded pixel value that then cannot scale. Font sizes in rem make the drift impossible in the first place.

Unit by Unit: The Decision Table

JobFirst choiceWhy
Body and heading font sizesremScales with user preference, never compounds
Line heightunitless numberMultiplies the font size; stays proportional on every element
Component padding and gapsemTracks the component's own type size
Page layout spacingremConsistent rhythm tied to the root scale
Container widths for textrem or chMeasure follows type, not device pixels
Media query breakpointsemRespond to both window width and user font size
Borders and hairlinespxExact, tiny, and not a legibility feature
Icon sizes inline with textemIcons join the text's own scale

Making Fluid Type Safe: Min, Max, and the Middle

Viewport units enter this conversation because designers want headings that grow with big screens. Used alone, a font-size in vw ignores the reader's root size entirely, the same defect as px with extra steps. The clamp() pattern fixes it by pairing a rem floor and ceiling with a viewport-based middle:

font-size: clamp(1.125rem, 1rem + 1vw, 2rem);

Read it as: never smaller than 1.125rem, never larger than 2rem, and between those, grow with the viewport. Set the two rem bounds first, from your type scale, and the middle term only chooses where between them the current window lands. A heading built this way can flex across layouts without ever dropping below the size the reader's settings would have given them, and without ballooning on a cinema display. Body text should not flex this way at all; 1rem is already the reader's chosen size, and the correct fluidity for paragraphs is a fixed rem size with a comfortable measure.

Two Units Worth Knowing by Name

ch is, in MDN's words, the advance measure of the glyph 0 (zero) in the element's font. Text columns constrained with a max-width in ch follow the font, so a reader's larger text gets a proportionally wider column rather than the same narrow slot with bigger letters. Two cautions: a ch is the width of a zero, not of an average letter, so a column of 65 ch holds a different number of real characters in a narrow font than in a wide one; and because the metric comes from the active font, the column width shifts when the family changes or a fallback font is showing. We measured how far apart the two can drift in our guide to line length and line height.

Percent on the root is the quiet hero of this whole guide. html set to 100 percent simply adopts the reader's default; any lower percentage scales the whole site relative to their choice. The root is the one place where a percent, and effectively an em mindset, is not a compounding hazard but the entire point.

Print stylesheets follow the same rules with one wrinkle: on a printer, MDN notes, a CSS pixel is tied to 1/96 of an inch, while rem and em are still defined by font sizes. A rem-based screen scale therefore prints in the same proportions without a separate print typography system.

None of this requires a framework or a build step. It is a dozen decisions made once in a stylesheet's foundations and inherited by the components that follow, which is why unit discipline is cheap to adopt at the start of a project and tedious to retrofit. Fixing a mature stylesheet is still worthwhile, and the audit below shows where to start: converting a base style converts everything that inherits from it.

Converting a Spacing Scale, Step by Step

Type sizes get most of the attention, but spacing is where a design file usually carries the most pixel values. A typical 4-pixel-based spacing scale converts cleanly at a 16px root, because every step divides evenly:

Spacing tokenDesign filerem at a 16px rootAt a 20px reader default
space-14px0.25rem5px
space-28px0.5rem10px
space-312px0.75rem15px
space-416px1rem20px
space-624px1.5rem30px
space-832px2rem40px
space-1248px3rem60px
space-1664px4rem80px

The last column is the argument for converting spacing at all. If type grows to 20px for a reader who set a larger default, but padding and gaps stay at their pixel values, text crowds against its container edges and line lengths change. Converting the scale keeps the proportions the designer drew. The exceptions are the same ones that apply everywhere else: a 1px divider or a focus ring offset can stay in pixels, because their job is to be a fixed, crisp line rather than to scale with reading size.

One practical tip: convert the token definitions, not every usage. If the scale lives in one file as custom properties, the conversion is eight lines, and every component that consumes the tokens follows automatically. The px to rem converter handles the arithmetic when a step does not divide evenly, such as 18px (1.125rem) or 22px (1.375rem).

Auditing an Existing Stylesheet for Unit Problems

Search the CSS for these six patterns, starting with the root, because a root fix reaches every rem value below it:

  • Root untouched or percentage-based: the html font size is never set in px, so reader settings flow through.
  • No px font sizes below the root: every text size is in rem (or inherits), including small print and captions.
  • Spacing units split on purpose: em inside components, rem for page rhythm, by convention not accident.
  • Breakpoints in em: media queries respond to user font size as well as width.
  • 200 percent resize tested: text scales to double size with nothing clipped, overlapped, or cut off, per WCAG 1.4.4.
  • Containers grow: no fixed pixel heights on text blocks whose content must reflow at large sizes.

Container Query Units: Sizing to the Component, Not the Window

Everything above sizes things against the root or against the window. Components increasingly need a third reference: the box they are placed in. A card that sits in a wide main column on one page and a narrow sidebar on another should not take its sizes from the viewport, which is the same on both pages. Container query units answer that.

MDN's reference defines them against the query container: one cqw is 1 percent of the container's width, one cqh 1 percent of its height, one cqi and one cqb 1 percent of its inline and block size, and cqmin and cqmax the smaller or larger of the two. A container is an ancestor declared with container-type: inline-size (or size). MDN adds that if no eligible container is available, the unit "defaults to the small viewport unit for that axis", so a cqi with no container quietly behaves like svi.

For designers the useful one is cqi, because inline size is width in horizontal writing and the reliable axis to query. A card heading written as font-size: clamp(1.125rem, 1rem + 2cqi, 1.75rem) grows with the card rather than the window: in a 300-pixel sidebar container, the container term (2 percent of 300) is 6 pixels and the heading computes to 22px (16 + 6); in a 900-pixel main column the same term is 18 pixels, 16 + 18 = 34, and the clamp caps it at its 28px ceiling (1.75rem). The rem bounds do the same job here as in the fluid-type section above: whatever the container does, the text never drops below the size the reader's settings would give it, and it still scales with their default font size because both bounds are in rem.

Two cautions. Container units on their own share the defect of vw for type: a heading in pure cqi ignores the reader's text-size setting, so always wrap them in a clamp() with rem bounds. And containment changes layout: MDN's container-type reference says an inline-size container's inline size "can be computed in isolation, ignoring the child elements". Declare it on layout wrappers whose width comes from the page grid, such as card grids and sidebars, not on elements that should shrink to fit their content.

Questions About CSS Units

Is 1rem always 16px?

Only when the reader's root font size is 16px. 1rem equals the html element's computed font size; MDN calls 16px a common browser default, and users can raise or lower it in settings. That variability is the feature, not a bug; it is how rem-based sites honor reader preferences.

Should I set html font-size to 62.5 percent to make the math easy?

You can, and it does respect user settings because it is a percentage of their default. The cost is surprise: every pasted component, library, and new teammate expects 1rem to relate to a 16px default. Plain conversions, a quick converter check, and a documented type scale age better.

Why do my nested lists keep getting bigger?

Their font sizes are set in em or percent, which multiply down the tree. Set font-size in rem throughout, and keep em for spacing only, and compounding disappears while component-relative padding still works.

Are pixels ever the right unit for text?

For a truly fixed artifact, a canvas game or an image-replacement graphic, px can be defensible, with the understanding that the reader's text setting will not move it. For text that forms part of an HTML document, rem is the unit that meets the resize requirement without extra work.

What about vw and vh for type?

Viewport units size text to the window, which is a different job. They are useful inside a clamp() that also sets rem-based minimums and maximums, so text can flex with layout without ever dropping below what the reader's root size would give them. A viewport unit alone ignores the reader's default font size setting, so do not let one stand by itself for body or heading sizes. For layout heights on phones, where 100vh and the browser toolbars disagree, see which of vh, svh, lvh and dvh to use.

Do em breakpoints change my layout for users with large default text?

Yes, and that is the intent. A reader whose default is 20px gets your narrower layouts at wider windows than a 16px reader does, because their larger text needs the narrower measure sooner. The layout adapts to the reader instead of interrogating the device.

Keep Going: Tools and Specs

Open the PX to REM converter while you edit the stylesheet; it converts both ways at any root size. For the scale itself, the typography scale system guide builds a rem-based modular scale for a whole site, and the WCAG compliance and accessibility guide holds the full checklist that the resize rule belongs to. Color is sizing's partner discipline: accessible color systems covers contrast checks for light and dark themes.

Checked on October 28, 2026 against: WCAG 2.1 Success Criterion 1.4.4 and its Understanding document; Media Queries Level 4 (W3C Candidate Recommendation Draft, 19 February 2026, section 1.3 on units); and MDN's CSS length reference (last modified July 8, 2026), plus its line-height, font-size and container-type references. The 200 percent card, breakpoint and container tables are our own arithmetic with the inputs stated. Maintained by the Lucky Graphics editorial team.