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

em or %?

I searched on the web for the difference between em en %, I found this article.

http://kyleschaeffer.com/development/css-font-size-em-vs-px-vs-pt-vs/

Can someone tell me why a lot of people use the em still.

Just like in this tutorial.

Friendly regards,

Frans de Haan,

1 Answer

Robert Stefanic
Robert Stefanic
35,170 Points

It could be preference. I would personally suggest someone to use % over em, but using em isn't wrong.

It's just easier to reason about what's going on with %. If I'm reading someone's code, and I see a %, I know it's a percentage relative to the parent element. In my opinion, it's just easier to read, and therefore, it's easier to reason about.

When someone uses em, you have to take into account what the parent element's size is in pixels, and then do some math in order to figure out the value you want. Em is an abstraction of pixel values, and in order to figure out the size of an element, you have to think about what the parent's size is, and then multiply it by the em. It's just a bit odd to work with at times.