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

main header

If the main header font size is set at 2 ems then why is it displaying bigger than 32px?

2 Answers

Aakash Srivastava
Aakash Srivastava
5,415 Points

Hey Maddie Duffy , em unit is relative unit .
Now , if main header font size is set at 2 ems , then it will displaying 32 px only when the font-size of body(which is parent of main header) is set to 1 em or 16 px .
Let's look at an example:

body{
font-size: 1em;        // it is 16 px
}

.main-header{
font-size: 2em;       //  it will be 32 px  ( 16 * 2 )
}

Take another case :

body{
font-size: 2em;     // // it is 32 px
}

.main-header{
font-size: 2em;       //  it will be 64px  ( 32 * 2 )
}

Hope it helped :)

Thank you!!! Helped a lot!

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

The em unit is a relative unit. So it's probably displaying a size that is relative to its parent element.

"Relative length units are relative to other length values. "

So it 1 em is the equivalent of 16 pixels then 2 em will be 32 pixels.