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 trialNika Lea Erwin
2,754 PointsWhy define some values in px, some in % and some in em? Why wouldn't you always want % relative to screen size?
Doesn't it get confusing if you have different units all in the same code?
2 Answers
Adam Sackfield
Courses Plus Student 19,663 PointsI don't know why you would use more than one unit. I tend to use 'em' and that's it pretty much.
Neil Anuskiewicz
11,007 PointsI think it's the tool for the job sort of situation. I do share your not quite understanding when px would be used as it's not scalable but some designer might have a reason to create a pixel perfect design. It's not scalable but maybe scalable is not always necessary. Or maybe it is scalable on some devices?
Since em is relative to the parent element, it's scalable. So if the parent element yields 16pt then .5em would be 8pt and 2em would be 32pt., which is cool.
Don't forget root ems (rems), which are always relative to the font size of the <HTML> element.
I think you're right that % seems very useful but I think em is sort of becoming standard (maybe I'm wrong) and it is scalable, But Maybe someone more knowledgeable than me will weigh in on the subtitles on when to use each and why.