To convert CSS pixels (px) to root em (rem) units, divide the pixel value by the computed font size of the root <html> element: rem = px ÷ Root Font Size. Because all modern desktop and mobile browsers default to a 16px root font size, the standard conversion formula is rem = px ÷ 16 (making 1px = 0.0625rem and 16px = 1rem).
Unlike fixed px values, rem units scale proportionally when a visitor adjusts their browser's default text size for readability. Converting typography, padding, and layout spacing from pixels to rem preserves visual hierarchy across devices while maintaining compliance with international web accessibility standards.
Exact Conversion Formula & W3C CSS Standards
The rem unit is standardized in the W3C CSS Values and Units Module (Levels 3 and 4), where it is defined as equal to the computed value of font-size on the root element (<html>). Using formal mathematical ratio notation aligned with ISO 80000-2, the conversion between CSS pixels and rem is a linear scale factor determined by the root base r:
rem = px ÷ r and inversely px = rem × r
Under the W3C CSS specification, 1px is not strictly a physical device pixel; it is a reference pixel defined as 1/96 of 1 CSS inch (approximately 0.2646 mm at normal viewing distance, scaled automatically by device pixel ratio on Retina/HiDPI displays). Meanwhile, W3C WCAG 2.1 and 2.2 Success Criterion 1.4.4 (Resize Text) requires that text can be resized up to 200% without assistive technology and without loss of content or functionality.
If a stylesheet sets font-size: 16px directly on paragraphs, changing the browser's base font setting has no effect on that text. By contrast, defining font-size: 1rem allows the browser's root value (16px default, or 20px / 24px when enlarged by the user) to flow cleanly through every typographic and spacing token in the design system.
Step-by-Step Worked Practical Examples
1. Standard 16px Root Design Token Conversion
A Figma handoff specifies a modal dialog with a 28px title, 18px body text, and 24px internal padding. Your CSS leaves the browser's default 16px root font size untouched.
- Modal title:
28 ÷ 16 = 1.75rem. - Body copy:
18 ÷ 16 = 1.125rem. - Card padding:
24 ÷ 16 = 1.5rem.
2. Using the 62.5% Root Percentage Scale (10px Base)
Many engineering teams set html { font-size: 62.5%; } alongside body { font-size: 1.6rem; } so that 1rem equals 10px (16 × 0.625 = 10px), allowing instant mental division by 10. Suppose you implement a 14px metadata badge and 36px hero subtitle:
- Metadata badge:
14 ÷ 10 = 1.4rem. - Hero subtitle:
36 ÷ 10 = 3.6rem. - Base body copy remains
1.6rem(16pxat default zoom).
3. Accessibility Browser Font Override (20px User Preference)
Suppose a low-vision reader increases their Chrome default font size from 16px to 20px (125% scale).
- A section heading authored as
2.25rem(originally36pxat16pxroot) recalculates to2.25 × 20 = 45px. - Body text authored as
1.125rem(originally18px) scales to1.125 × 20 = 22.5px. - A hardcoded
18pxelement would remain trapped at18px, breaking proportional visual hierarchy.
Quick Reference Conversion Table
The table below lists high-frequency UI pixel values converted for both the standard 16px browser default and the 10px (62.5%) root configuration.
Pixels (px) | REM (16px Default) | REM (10px / 62.5% Root) | Typical UI Role |
|---|---|---|---|
| 4px | 0.25rem | 0.4rem | Micro spacing / focus ring offset |
| 8px | 0.5rem | 0.8rem | Compact inline gap / chip padding |
| 12px | 0.75rem | 1.2rem | Small helper caption / badge text |
| 14px | 0.875rem | 1.4rem | Secondary UI label / table cell text |
| 16px | 1rem | 1.6rem | Browser default body paragraph |
| 18px | 1.125rem | 1.8rem | Long-form editorial body text |
| 20px | 1.25rem | 2rem | Lead paragraph / card heading |
| 24px | 1.5rem | 2.4rem | Subsection heading (h3) / gutter |
| 32px | 2rem | 3.2rem | Major section heading (h2) |
| 48px | 3rem | 4.8rem | Hero display title (h1) |
Industry Use Cases, Regional Pitfalls & Common Mistakes
Frontend engineers and UI designers frequently encounter subtle CSS rendering bugs when migrating pixel-based design specs into scalable stylesheets.
- Hardcoding
html { font-size: 10px; }: Some developers override the root with a fixed10pxinstead of62.5%to achieve base-10 math. Settinghtmlinpxoverrides the user's browser font-size preference completely, breaking accessibility compliance. Always express any custom root scale as a percentage (62.5%) or keep100%(16px). - Confusing
remwithemCompounding: Usingemfor nested lists or reusable card components causes multiplication compounding: if a parent card setsfont-size: 1.2emand a child badge inside it setsfont-size: 0.85em, the child evaluates to1.2 × 0.85 = 1.02of the base rather than0.85. Useremfor global font sizes, layout gutters, and breakpoints, and reserveemfor properties tied to a single element's own text size (such as button padding ormargin-bottomon headings). - Converting
1pxHairline Borders torem: Converting1pxor2pxborders to0.0625remoften triggers subpixel rounding inconsistencies (0.875pxor1.25px) when users zoom, causing borders to disappear or look blurry on non-HiDPI displays. Keep thin borders (1px,2px) and box-shadow blurs inpx, while converting typography, component dimensions, and margins torem. - Mixing
pxBreakpoints withremContent: If a sidebar usesremwidths (18rem) while media queries usepx(@media (min-width: 768px)), enlarging the browser font size to24pxexpands the sidebar to432pxwithout shifting the breakpoint, squeezing main content. Authoring media queries inrem(48rem) keeps layout shifts synchronized with text scaling.