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 CSS Basics (2014) Understanding Values and Units Em Units

Corey Rodney
Corey Rodney
3,075 Points

When and why most people use EM over px

After doing some research on my own I notice that in the header most if not all use em over px. My question is since they both do the same thing is there a benefit for using em over just simply using px?

1 Answer

Steven Parker
Steven Parker
216,057 Points

An advantage of using "em" units is when you are sizing something that contains text, it will grow or shrink to remain proportional to the text if the font size is changed at a later time.

Pixel units are a good choice when you want to size something that won't change, such as an image container.