compelling case for using px instead of em and rem. rem is so sweet
Why you should use px, not em
Using em is a very elegant way to define both your text size and your layout. It keeps every element balanced and easily sizable. I’veused it before. It’s a pain.
Fonts need precision to look sharp
Let’s say your default font-size is set to 16px. You have titles at 2remand subtitles at 1.5rem. Fabulous! Your semantic hierarchy matches your visual one. If you were to change your default text size to 15px, you’d maintain that hierarchy.
But not all font sizes are equal… Considering the text of this website:
Every font needs its own specific size
Another problem with em arises when you want to change the font family, because every font renders differently at each size:
...
Just use pixels
If you want sharp precise interfaces, stick to px:
- you’ll avoid any cumbersome calculations that involve 4 decimals
- just by looking at a CSS rule, you’ll know exactly how it will look like because there’s no dependency
- preprocessors like Sass allow easy maintenance anyway: you can have global variables for sizes, or use mixins to define variations for your elements
- you’ll be able to align different types of elements that each require their own font-size