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 trialZach Saul
11,156 PointsPractical difference between specifying font size with "em" units or percentages?
What is the difference (if there is one) between using "em" units to specify font size and using percentages?
it's my understanding both are relative to the font size of their parent element, and both use a version of percentages (2 em = 200%) as they reference the same thing.
I am essentially asking if these two pieces of code are at all different:
p { font-size: 2em; }
OR
p { font-size: 200%; }
are there in situations where i should use one as opposed to the other??
1 Answer
Ivan Burda
10,897 PointsI have tried to find out an answer to your question because I would like to know it too. The outcome of my efforts is that both "em" and "%" are relatively safe and mutually replaceable. Some problems may arise when the browser allows you to change the default font size. Check the two articles below for more information. I would not be worried too much about using any of the two units, however, I would be very careful with absolute unitss such as pixels, dots, etc.
1) http://stackoverflow.com/questions/132685/font-size-in-css-or-em 2)http://kyleschaeffer.com/development/css-font-size-em-vs-px-vs-pt-vs/ (this articles is not very recent though)