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

HTML How to Make a Website Adding Pages to a Website Style New Pages

Why 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

I don't know why you would use more than one unit. I tend to use 'em' and that's it pretty much.

Neil Anuskiewicz
Neil Anuskiewicz
11,007 Points

I 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.