Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.