px or em?

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
Ree
Forum Regular
Posts: 592
Joined: Fri Jun 10, 2005 1:43 am
Location: LT

px or em?

Post by Ree »

which is a more commonly used unit - em or px? or maybe there are specific cases when one or another should be used? would like to recieve your input on this.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

It depend on what you're doing.

For layouts I *almost* always would use px since the geometry can be critical.

I'm gonna slide slightly off-topic and bring in font-talk. pt vs. em... always always always use em for font sizes if it's something that's part of the main content of the page. pt font sizes are rendered differently across the operating systems and can make impossible reading on some system where it looks nice on others. Using pt also *generally* prevents the user from using the increase/decrease font size option in their browser and so you're putting a large rock on top of any accessibility ideas you may have considered in your design.

Layouts... px yes, or for full-width designs... %.
Ree
Forum Regular
Posts: 592
Joined: Fri Jun 10, 2005 1:43 am
Location: LT

Post by Ree »

yes, i indeed had in mind fonts when i posted, just forgot to mention. :P
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Re: px or em?

Post by Roja »

Ree wrote:which is a more commonly used unit - em or px? or maybe there are specific cases when one or another should be used? would like to recieve your input on this.
Oddly enough, it looks like you should use neither.

px is non-relative, which means that users can't view the text larger if they need to. (It locks the size).

em on the other hand is relative, and is thus cool. It lets the user do what they want.
MozillaKB wrote: However, 1 em is 10.06667 pixels, and 1 ex is 6 pixels. Therefore, ex units are recommended over em units, since they are more easily converted into evenly-rounding pixel values.
So it looks like ex is better! Personally, I've almost always used em's, and I see other places where they say different things about em units.

For once, I am not sure (pun intended), and more discussion is warmly invited.
thedamo
Forum Newbie
Posts: 9
Joined: Fri Jul 15, 2005 7:23 am
Location: Sydney Australia

Thanx for that

Post by thedamo »

Thankyou for that useful information. I have always used px. But I think i will need to change this habit.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

http://www.forum4designers.com/archive2 ... 80038.html -> argument against ex:
em (and ex) are in theory just as good as % but in practice they
trigger a few more browser bugs, so % is preferred for font-size. Use
em for scalable derived styles (such as padding). ex is further
screwed on several platforms where it is just treated as 0.5em rather
than as the correct value for the font in question.
http://css-discuss.incutio.com/
More specifically,
http://css-discuss.incutio.com/?page=UsingFontSize
Post Reply