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

CSS CSS Basics (2014) Understanding Values and Units Rem Units

Andy tran
Andy tran
7,112 Points

Converting px to em

So if body element font-size(parent) was to be 2em which is equal to 32px and we want to set h1(child) font-size to 26px, then we have to take 26px/32px to get em unit for h1 . Am i right? Do we have to do this every time or just use % instead since % also makes font size proportional to web page?

1 Answer

Steven Parker
Steven Parker
231,275 Points

Close, but if 2em is 32px, then the equivalent em size of 26px would be 26 / (32/2) or 26/16 or 1.625em.

You'd still need to calculate to convert to % instead of em, you would just put the decimal point in a different place.