= 1rem= 16pxThe quick brown fox
| Pixels | Rem | Em | Copy |
|---|---|---|---|
| 8px | 0.5rem | 0.5em | |
| 10px | 0.625rem | 0.625em | |
| 12px | 0.75rem | 0.75em | |
| 14px | 0.875rem | 0.875em | |
| 16px | 1rem | 1em | |
| 18px | 1.125rem | 1.125em | |
| 20px | 1.25rem | 1.25em | |
| 24px | 1.5rem | 1.5em | |
| 28px | 1.75rem | 1.75em | |
| 32px | 2rem | 2em | |
| 36px | 2.25rem | 2.25em | |
| 40px | 2.5rem | 2.5em | |
| 48px | 3rem | 3em | |
| 56px | 3.5rem | 3.5em | |
| 64px | 4rem | 4em | |
| 72px | 4.5rem | 4.5em | |
| 80px | 5rem | 5em | |
| 96px | 6rem | 6em |
Understanding CSS Units: Px, Rem, and Em
CSS offers a variety of units for sizing elements, but three dominate everyday development: pixels, rem, and em. Pixels are the simplest — they map to device pixels (adjusted by the device pixel ratio) and produce predictable, rigid layouts. But rigidity is a drawback when building accessible, responsive interfaces.
Rem and em are relative units that create fluid, scalable designs. Rem is always relative to the root element's font size (typically 16px), making it predictable and consistent. Em is relative to the current element's parent font size, which makes it powerful for component-scoped scaling but tricky when elements are deeply nested.
Rem vs Em vs Px: When to Use Each
Use rem as your default unit for font sizes, spacing, and layout dimensions. It creates a consistent scale anchored to a single base value, and it respects user accessibility settings. If a user increases their browser's default font size, rem-based layouts adapt automatically.
Use em when you want an element to scale relative to its own font size — for example, padding on a button that should always be proportional to its text. Use px for borders, outlines, box shadows, and any detail where you need pixel-precise control that shouldn't change with font size.
Responsive Design with Relative Units
Responsive design is about more than media queries. Using relative units like rem ensures your typography, spacing, and layout proportions stay harmonious across screen sizes. A heading set to 2rem is always twice the body text, regardless of the base size.
Many modern CSS frameworks, including Tailwind CSS, use a rem-based spacing scale (0.25rem, 0.5rem, 1rem, etc.) precisely for this reason. Combined with fluid typography techniques (clamp() with rem), relative units enable designs that smoothly adapt from mobile to ultrawide displays without abrupt breakpoints.
Accessibility and CSS Units
WCAG Success Criterion 1.4.4 requires that text can be resized up to 200% without loss of content or functionality. Layouts built with px-based font sizes often break this requirement because they don't respond to the user's text size preferences. Rem-based sizing solves this by inheriting from the root font size.
Beyond compliance, relative units are simply good UX. Users with low vision, dyslexia, or cognitive disabilities often adjust their browser's default font size. Respecting that preference with rem/em units costs nothing in development effort but significantly improves usability for millions of people.
Frequently Asked Questions
Related Tools
Explore More Tools
Find this tool useful? Buy us a coffee to keep DuskTools free and ad-light.