Course contentsShow
← Web Development
Lesson 155 of 2,9823. CSS FundamentalsFree lesson

Relative Units: em and rem

Understand em (relative to parent font size) and rem (relative to root), enabling scalable typography.

Relative Units: em and rem

What you'll learn: How em and rem create scalable, flexible typography by sizing elements relative to font sizes rather than fixed pixels.

What Are Relative Font Units?

Unlike absolute units (px, pt, cm) that stay fixed, em and rem scale based on font sizes. This makes your designs more flexible and responsive—when a user adjusts their browser's default font size or you change a parent element's text size, everything adjusts proportionally.

Understanding em

The em unit is relative to the parent element's font size. If a parent has font-size: 16px, then 1em = 16px, 2em = 32px, and 0.5em = 8px.

The catch: em compounds. If you nest elements with em sizing, each level multiplies. A child with font-size: 1.5em inside a parent that's already 1.5em becomes 1.5 × 1.5 = 2.25× the original size.

Analogy: Think of em like saying "one serving size." If your parent's serving is a large bowl, "one serving" means large. If the parent's serving is a small cup, "one serving" means small.

Understanding rem

The rem unit (root em) is relative to the root element's font size—the <html> element. If your root is 16px (browser default), 1rem = 16px everywhere, regardless of parent sizing.

The benefit: No compounding. 1.5rem always means the same size throughout your entire document.

Analogy: rem is like measuring from a universal ruler. No matter how deep you nest, you're always measuring from the same starting point.

Why Use Them?

Relative units make your site accessible and maintainable. Users who need larger text can adjust their browser settings, and your entire layout scales gracefully.

Key Takeaway: Use em for sizing relative to a parent element (like button padding), and rem for consistent, predictable spacing and typography throughout your site—both enable scalable, accessible designs.