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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.