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 trialJorge Vega
Front End Web Development Techdegree Student 2,905 PointsWhen to use rem, em or px?
Hello!
I still don't get when to use rem, ems, px. How do you know when and where to use them?
Thank you in advance
Cheers!!
2 Answers
Steven Parker
231,184 PointsIf you look for terms like "em vs rem" in a search engine, you'll discover there's a bit of controversy around this decision. One post I saw even had the amusing title of "CSS Unit Battle: EMs Vs. REMsβ¦FIGHT!"
They are both font-size relative units, but the essential difference is that ems are relative to the parent element, making them a more modular choice, and rems are relative to the document root, making them simpler if a bit more rigid to the design. It may take some experimentation and/or experience to get a sense for which you prefer in what situations. And it may not be the same as another developer.
Pixels (px) on the other hand, are not relative and are a good choice for dimensions of things that you don't want to change along with font sizes at all.
But there's rarely only one "right" choice. It's mostly a matter of considering what role the thing being sized has in the overall design, along with your own preferences. It's one of those things that should become more clear with a bit of experience and/or experimentation.
Jorge Vega
Front End Web Development Techdegree Student 2,905 PointsThank you Steven!
I do also think I need some more practice and experience to get more familiar with these units.
thanks a lot!
Cheers,
Jorge