← Guides

CSS Units Explained: px, rem, em and pt

What each unit is for

CSS offers many length units, but four do most of the work on real projects. The useful question is not which one is "best" but which reference each unit measures against, because that reference decides how the value responds to user settings, nesting and zoom.

UnitRelative toTypical useResponds to user font size
pxCSS pixel (1/96 inch at reference)Borders, shadows, hairline detailNo
remRoot element font sizePage spacing, typography, layoutYes
emThe element's own computed font sizeComponent padding that scales with textYes, through inheritance
pt1/72 inchPrint stylesheets and PDF outputDepends on print context

px is a CSS pixel, not a physical pixel

One CSS pixel equals 1/96 of an inch at the reference viewing distance, but on a high-density screen it may cover several physical pixels. That abstraction is deliberate: a 1px border stays visually consistent across devices instead of becoming invisible on a retina display. CSS px also scale with browser zoom, so a page zooms as a whole rather than leaving fixed-size elements behind.

px is still appropriate for values that should not grow with text: a 1px divider, a 2px focus ring, a 4px shadow offset. The mistake is using px for body copy, container widths tied to text, or anything that a user might need to enlarge.

rem and the root font size

1rem equals the computed font size of the html element. With the browser default of 16px, 1rem = 16px, 0.875rem = 14px, and 1.5rem = 24px. If a user sets the browser default to 20px, every rem value grows by 25%, which is exactly the behaviour accessibility guidance wants.

Example: on a page with a 16px root, 1.25rem is 20px and 2rem is 32px. The same declaration on a 20px root produces 25px and 40px. A px declaration would stay fixed in both cases.

Using rem for spacing and typography gives one global lever: change the root size and the whole layout scales in proportion. Use rem for margins, padding, font sizes and breakpoint values that should follow text size, and keep px for borders and other decorative constants.

em compounds through nesting

em is relative to the font size of the element itself, not the root. For an element with a 20px font, padding: 1em is 20px. For its child with a 16px font, padding: 1em is 16px. The same declaration produces different pixels in different contexts, which is useful for self-contained components and dangerous for deep trees.

Nesting multiplies. If three nested elements each set font-size: 0.9em from a 16px base, the sizes become 14.4px, then 12.96px, then 11.664px. A small reduction intended for one level shrinks the text by more than a quarter after three. Example: 0.9 em applied twice gives 0.81 em, and three times gives 0.729 em.

Use em deliberately for a button's padding that should track its label size, and prefer rem for global typography where compounding would be accidental.

pt belongs to print

A point is 1/72 of an inch, so it describes a physical distance. On screen, browsers treat 1pt as roughly 1.333px at the reference density, which makes pt behave like a slightly awkward px. In a print stylesheet or a PDF generator, pt is the natural unit for font sizes, margins and page geometry, because the output medium has a fixed physical size.

Example: 12pt = 16px and 9pt = 12px. Converting a print specification of 10.5pt gives 14px. Use pt inside @media print, not for screen layout, where it adds confusion without improving output.

Zoom, user font settings and accessibility

Browser zoom scales the CSS pixel, so a px-based layout still grows when the user zooms. What px does not respect is a user's chosen default font size in browser settings. Someone who sets 20px as their preferred reading size will see px copy unchanged, while rem-based copy expands. WCAG 1.4.4 asks that text can be resized to 200% without loss of content or function, and relative units are the simplest way to meet that in practice.

Fixed heights and overflow hidden are the usual culprits: a 48px-tall button with overflow: hidden clips its label when text grows. Prefer minimum heights and allow wrapping, and test the page at 200% zoom and with an enlarged browser default font.

Common px-to-rem values at a 16px root

pxremTypical role
12px0.75remSmall labels, captions
14px0.875remSecondary text
16px1remBody text, base spacing unit
18px1.125remComfortable body text
20px1.25remSection labels
24px1.5remCard headings

The conversion is simply the pixel value divided by the root size: 18 / 16 = 1.125, and 24 / 16 = 1.5. At a 20px root, the same 24px target becomes 1.2rem, which is why hardcoding converted values assumes the root never changes.

The 62.5% trick and its trade-offs

A widely copied pattern sets html { font-size: 62.5% }, which makes the root 10px when the browser default is 16px. Then 1.2rem = 12px and 1.6rem = 16px, and converting from a pixel design is mental arithmetic. The cost is that the root now depends on a percentage of the user's setting: a user who chose 20px gets a 12.5px root and smaller text than intended. It also makes 1rem an unusually small base that is easy to misuse.

Keeping html { font-size: 100% } and writing 0.875rem instead of 1.4rem costs a little arithmetic but preserves the user's preference exactly. If a project does use 62.5%, document it, audit every rem value for unintended small sizes, and never combine it with px font sizes on body copy.

Checklist for choosing a unit

  • Use rem for type and spacing. It respects the user's root font size.
  • Use px for borders and fine detail. Those should stay crisp and constant.
  • Use em only when compounding is intended. Check nested components before shipping.
  • Use pt only for print. Screen stylesheets should stay in px, rem or em.
  • Avoid fixed heights around text. Let containers grow when the font size changes.
  • Test at 200% zoom and a larger default font. Both reveal different failures.

Convert between px, rem, em and pt with a configurable root size using our CSS unit converter, which also shows a common-size reference table. For dimensions in images, see resize vs crop; for colour values used alongside these sizes, see HEX, RGB and HSL.

Try it yourself: open the CSS Unit Converter →