“Pixel” vs “em” in CSS

A pixel is a dot on your computer screen. Specifying font sizes in pixels is great when you want the user to see exactly on their screen what you designed on yours, though it assumes your screens are of similar size.

What if the user is using a screen that’s a very different size from yours, though (like a smartphone screen)? Enter ems. (Don’t confuse these with the tags we use for emphasis!)

The font-size unit em is a relative measure: one em is equal to the default font size on whatever screen the user is using. That makes it great for smartphone screens, since it doesn’t try to tell the smartphone exactly how big to make a font: it just says, “Hey, 1em is the font size that you normally use, so 2em is twice as big and 0.5em is half that size!”

Happy Reading!

Leave a Reply
