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

Jack Hou
Jack Hou
6,975 Points

Question about the use of em

So in many videos, there is the use of em when choosing font sizes. From what I know so far, 1 em is equal to 16px, but why do some of the videos say in certain example that 1 em is equal to 18px. Did they change the base font size ? if so, how do you do it?

John Locke
John Locke
15,479 Points

Hi Jack: 16px is usually equal to 1em, as most browsers have it set like that by default. To change the base size, simply declare something like body {font-size: 18px;} in your CSS.

Jack Hou
Jack Hou
6,975 Points

So 1 em can be whatever you want it to be as long as it's the base font size in the body? so if i declare body { font-size : 72px } then 1em will be 72px?

Thanks for taking the time to answer!

John Locke
John Locke
15,479 Points

Yes. Whatever you set the base font-size to, that new size will become 1em.

1 Answer

Just adding that em units cascade or are relative to their parent's size (not always the body) which can cause extra work in resetting nested containers etc. back to 1em. If you want a unit that is based on the html body page only it's better to use the CSS3 rem unit (root em) which is supported in modern browsers and ie9+ or just provide a px fallback.