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

Why did you use the rem unit for the code text?

Guil used the rem unit for the first time. However he didn't really tell us why he chose that for this video. I'm just wondering why he used the rem unit and when should we use it?

1 Answer

Hi Bappy,

The differance between em and rem is as follows.

rem is always a constant, so if you had your root font size of 1rem (16px) and you had some paragraphs nested within other elements that all had different font sizes assigned to them, then you decided to set the font size of your h3 text to 2rem ( 32px) then you would be certain it was going to be 32px.

If you did the same thing using em you can run into problems with the em unit inheriting font sizes from its parent element, for example.
If you set the nav font size to 20px then you had a paragraph within the nav and you set the font size to 1.5em you wouldn't get 24px you would get 30px because the nav was already set to 20px.

I really hope that makes sense :)