The debate between using root ems (rem) and pixels (px) has been a cornerstone of CSS discussions for years. While both units have their place in modern web development, understanding when and where to use each can dramatically impact your site’s accessibility and maintainability.
The Case for REM
REM units are relative to the root font size of the document, usually defined on the <html> element. The browser default is typically 16px. By using rem, you empower users who rely on custom browser font sizes for better readability. If a user sets their default browser font size to 24px, a layout built with rem will proportionally scale, whereas a layout hardcoded with pixels might remain stubbornly tiny.
Accessibility First
Accessibility is non-negotiable. Modern tooling and design systems champion rem for typography, padding, and margins to ensure interfaces remain robust across different visual needs. When you size text in rem, every browser zoom level and every user font preference works in your favor instead of against you.
Need to convert units quickly?
Switch seamlessly between px, rem, and em in seconds.
When Pixels Still Make Sense
Despite the overwhelming benefits of rem for typography and layout structure, pixels are not obsolete. They are absolute units, which means 1px is always 1px. This precision is crucial for:
- Borders: You rarely want a 1px border to scale up to 1.5px just because the user increased their font size.
- Media queries (sometimes): While some prefer em or rem for breakpoints, px is still widely used and arguably easier to reason about when designing for specific device widths.
- Canvas and SVG elements: Drawing strict geometric shapes often requires absolute coordinate systems.
How to Convert Between REM and PX
The math is simple once you know your root font size. To convert px to rem, divide the pixel value by the root font size:
rem = px / root-font-size
32px / 16px = 2rem
20px / 16px = 1.25rem
To convert rem back to px, multiply the rem value by the root font size. For anything other than the 16px default, you will want a converter that lets you adjust the root size instead of doing the division by hand.
The Verdict
The industry standard leans heavily towards REM for layout and typography and PX for micro-details like borders or specific absolute positioning. Adopting this hybrid approach ensures your designs are both resilient and accessible without sacrificing crisp rendering where it matters most.
When you adopt a rem-first approach, check every new value against your design tokens. A quick conversion while you style will keep your codebase consistent and your users comfortable.