Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

CSS How to Make a Website Customizing Colors and Fonts Resize Text

Ben Brenton
Ben Brenton
266 Points

em vs px for multi-platform use

For a project which is to be used on computer, tablets, phones etc., surely em is better to use as it adjusts with the screen it is on, rather than pixel, which is more defined? Is this correct, and which would I be better using? Also, if this is indeed a correct way of looking at it, why would you use both values in your CSS? Surely you would go with one or the other?

1 Answer

Thas Eagans
PLUS
Thas Eagans
Courses Plus Student 2,533 Points

Em is relative, whereas PX kind of locks you into a fixed measurement. What I sometimes do is use PX in a fluid design when i want the spacing or margin to remain fixed regardless of what size screen its on. For instance.... I want div 1 to have a 20px top margin from div 2.

I actually prefer to use rem instead of em. Em is based on its parent element, whereas rem is based on the root element. This prevents some unnecessary headaches if a parent container changes it's font size.

</TREagans>

Ben Brenton
Ben Brenton
266 Points

Thank you for clearing that up for me!