Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS CSS Basics (2014) Understanding Values and Units Em Units

Trying to wrap my head around the "compounding effect". Can someone try and explain it using a different approach?

Thanks in advance.

10 Answers

Hey Ryan, the compounding effect is based purely upon the fact that any value specified in ems for a given property is going to be rendered by the browser based on its parent element's value for the same property. Check out this generic example:

<div>
  <p>This text may be bigger than you expect!</p>
</div>
div {
  font-size: 1.5em;
}

p {
  font-size: 1.25em;
}

Normally, you'd expect a font-size of 1.25em to render at 20px (1.25 x default font size of 16px = 20px). However, in this case it compounds on its parent's font-size of 1.5em, leaving it to render at 16px x 1.25 x 1.5 = 30px. But it doesn't necessarily stop there. If, for instance, the div element were inside a body element whose font-size was also specified in ems, that value would become a part of the equation too. This is the compounding effect. You could maybe think of it like a snowball effect. The font-sizes snowball on top of each other and create an end-result that might be much different than you want.

Thanks Aaron. Your answer was very helpful.

Great answer Aaron! This wasn't as clear in the video. Appreciate it!

Thanks for this! Really helped clear up the idea of compounding ems.

Ditto!

Thank you!! Excellent, clear explanation. Much appreciated.

Thanks very much indeed. Your example with the math illustrates the relations in the compounding effect. Had watched the video three times and read the transcript but could not understand why/how the em was 'changing' i.e. where the new bigger numbers were coming from. The first example set was linked to an absolute number of 16px made sense but the last example was baffling.

Much appreciated, Aaron. My head started spinning for a second while watching the video. Your breakdown was super helpful.

Very helpful explanation Aaron, helped me to understand the compounding effect.

Did a quick google search after watching this video in attempt to clear that up but this is the best explanation I've received thus far! Thank you Aaron

Brilliant answer! Thanx Aaron!

Brilliant answer Aaron!! I was so confused after watching the video!!

Thank you Aaron! I was a bit lost after watching the video but feel I understand now :)

Thanks Aaron, the best explanation of this concept i could find! :)

Thanks dud.

Incredible delivery!