Jump to content

Why is it recommended to use em instead of px?


Goldeneye

Recommended Posts

Yeah, this is a really simple question. I've been doing CSS for quite a long time now and recently realized the (now) archaic ways of code.

 

So in my stylesheets, I've used pixels as my preferred measurement since I first got into CSS. So what makes em better than using px? Should I change all of my measurements to em? I've heard some people recommend the em measurement in place of px.

There isn't an absolute to this. In some situations ems are better, and in some situations, pixels are better. Ems are dynamic, so if you increase your text size then anything sized in ems will also expand. Pixels are fixed so they will stay the same regardless of text size. I prefer pixels for margins and padding, as they usually don't need to increase in size as the text size increases.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.