em vs rem in CSS — What's the Difference?
em is relative to the current element's font size (and compounds through nesting); rem is always relative to the root element's font size.
Published September 21, 2026
em is relative to the current element's font size (or its parent's), while rem is always relative to the root html font size. Use rem for predictable global scaling and em for components that should scale with their own text.
The concept
1rem equals the root font size (16px by default). Changing html { font-size } rescales everything using rem consistently.
em compounds: a 1.5em child inside a 1.5em parent is 2.25× the base. That is useful for padding that follows the button's text size, risky for nested font sizes.
Nested sizes
Practical examples
rem for type scale
h1 { font-size: 2rem; }
p { font-size: 1rem; }em for component-relative spacing
.btn { font-size: 1rem; padding: 0.5em 1em; }
.btn-lg { font-size: 1.5rem; } /* padding scales too */Respect user settings
html { font-size: 100%; } /* never fix px on html */Common mistakes
- Setting html { font-size: 10px } and breaking user preferences.
- Nesting em font sizes and getting runaway scaling.
- Using px for text and ignoring accessibility zoom.
Key takeaways
- rem = root-based, em = parent/self-based.
- Prefer rem for font sizes.
- Use em for spacing that follows local text.
FAQ
Do media queries use em or rem?
Both resolve against the browser default, not the page's html size.
Should I use px at all?
Fine for borders and fine details, not for text.