px vs em design/the (in)difference

published on:
March 03, 2010 / 12:06
comments

Last week Jens Meiert launched an article on the the reinstitution of px. Google is officially pulling the plug from IE6, which means the last browser to fail scaling px-defined fonts is yet another step closer to its death. A good time to re-evaluate the difference between px and em designs, keeping a strong focus on why they aren't as different as people usually believe.

quick recap

I assume most of you will know the basic difference between a px and em design, but I'll provide a quick recap anyway. px is a unit used for screens. It's an absolute measure that defines the size of an element based on the resolution of the client. On the other end we have em, which is a unit based on the value of the font-size. 1em equals the height of the current font-size (translated to px).

A good time ago em designs became in fashion as people starting thinking about the best way to handle font resizing using the browser. In an em design, the whole design is supposed to zoom with the font-size, making sure that none of the text spills over or out any graphical elements. Traditional px designs are not that flexible and retain their measures in absolute values, no matter what the font-size might be, often causing the layout to break.

Opera was the first to put a lid on the whole px/em argument by introducing a visual zoom to their browser. Rather than size the font, the whole site was visually zoomed. A nice feature, though you'll probably know that none of the browsers today can provide a perfect graphical zoom. Besides that, the method is somewhat flawed at its core because any images used will turn out fuzzy and unclear. Using em designs and simple font-sizing often gets you the better results (if it is designed as such of course).

designing for flexibility

The reason why px designs "sound" easier is because it is assumed that lengths are definite and unchanging. Once you receive the design, you can determine the width of elements, so trickier visual elements with rounded corners and drop shadows can be cut in lesser images. If you use images to create a box with rounded corners, inner fade and outer glow you'll quickly end up with 8 extra non-semantic and non-structural elements simply to accommodate all the background images. In a px design, you'll only need three.

At least, that's the common way of thinking. Which isn't exactly accurate if you like to write css with flexibility in mind. Assuming a width is definite is always a dangerous thing. I still have to participate in the first project where the design didn't receive some small touch-ups halfway through the development phase. Including changes in general layout, fe widening or reducing the width of side bars.

And even if you leave out the possibility of mid-project design changes, there's always the chance that a component will need to be used in an unforeseen area of the site. It isn't the first time I have to include an extra alert message in some or other component. If your css isn't flexible enough to accommodate these changes, you haven't done a very good job.

So even though you could start constructing your design in px values again, there is still the need to make the design of components flexible enough. An em design inherently focuses on this flexibility, making it clearer to incorporate this flexibility into your css. A px design might appear more definite, but if you're aiming to do a good job, you'll end up with just as much unnecessary html wrappers and just as many images.

so there's no difference?

parent>* {margin:1em;}

There is one major advantage that px designs have. The little css rule above defines a basic grid for all children of a certain parent. Since we are working with ems here, the actual size of the margin is dependent on the font-size of the children. While the rule gives the impression of ending up with an evenly spaced grid, the reality is that some of the children (often headings) will end up with a bigger margin because they have a larger font-size.

This is actually a pretty annoying problem (and my main reason for inserting a span element inside each heading I define). When applying a px design, you won't have this problem as the margin will be an absolute measure unrelated to the font-size of the child. The negative side is that when you size the font, the spacing between elements won't size accordingly, creating a somewhat muddled impression the more you size your font.

conclusion

While the need to avoid px for font-sizes is fading little by little, this doesn't mean you should simply switch back to the px design of the olden days. And when you do, make sure to remember that flexibility is a very strong asset in your work. Make sure that content can size horizontally and vertically without breaking the design, no matter whether you're implementing a px or em design.

As long as we'll have the need to use css background image to create certain graphical effects, the need for flexibility will stay and the difference between px and em design will remain rather futile.

The main thing to keep in mind is that whatever method you use and whatever design you are fed, designs are subject to change and implementations that are built to be resistant to such changes are of far more quality.

Comments

Bobby Jack

comment number
date
March 03, 2010 14:52

"While the need to avoid px for font-sizes is fading little by little"

Two reasons why I don't think this is true, and why I'll continue to avoid using 'px'-based font sizes wherever possible:

  1. As soon as you introduce an absolute font size into your CSS, you're creating something that will look good at one resolution, and flawed at all other screen resolutions. This is becoming a bigger problem over time as more varied resolutions are introduced.

  2. As soon as you use 'px', you're saying to the user "I don't care what your settings are, you're seeing text like this". That's almost exactly the same as point 1, but I want to emphasise the accessibility problems inherent in px-based font sizes.

Additionally, zoom is NOT an answer. As you pointed out, images often look terrible with zoom. Layouts break with zoom. I don't understand what the possible use case for 'zoom' (the equivalent of 'move your head closer to the screen') could ever be, in comparison with the obvious use-case for 'increase text size'. Page zoom has always felt to me like a hacky workaround put in place because some web designers have done such a bad job.

Niels Matthijs

comment number
date
March 03, 2010 15:10

As soon as you use 'px', you're saying to the user "I don't care what your settings are, you're seeing text like this"

Actually, only IE6 acts like that. Even if you define your font-size in px browsers will still adapt the size when the setting is changed in the browser.

Bobby Jack

comment number
date
March 03, 2010 16:53

Even if you define your font-size in px browsers will still adapt the size when the setting is changed in the browser.

Only if you're talking about minimum font size (which no browser, as far as I'm aware, handles particularly well - http://www.fiveminuteargument.com/blog/minimum-font-size). I was referring to default font size.

Niels Matthijs

comment number
date
March 03, 2010 18:40

Hmmmm, maybe I'm missing out on something, but even if you define a font-size in px on whatever element in your code, it will be adapted if you increase or decrease the font-size through your browser (normal text size (ctrl+ / ctrl-) in Firefox).

Or are you talking about something else altogether?

Bobby Jack

comment number
date
March 03, 2010 19:37

Oh, yes - if you increase the text, of course. But it's annoying to have to do that in the first place. Using percentages or em's will ensure the page is displayed to the user at a comfortable reading size according to their personal settings. Using pixel-based font-sizes ignores those settings.

Niels Matthijs

comment number
date
March 03, 2010 19:51

Pretty interesting, never really hit that feature before.

On the negative side, the standard value seems to be Times New Roman 16px (Firefox 3.6), which sounds awfully large to me. Of course I could change it, but since I've never hit the option before I'm quite sure many others aren't aware of it either.

It would make more sense if the "base font" option would be something you had to enable first.

Interesting feedback though!

Dan

comment number
date
March 13, 2010 12:32

The problem with the default browser text-size is it's unpredictability. As soon as the user changes it, you have no idea how big their text will turn out for a font-size of 100%. Ideally, exactly the size the user wants, but you can't be sure.

Either because they don't know a default setting exists and it will turn out too big (most likely - like you said, it's 16px by default), or they changed it to something smaller, and then setting a font-size of anything lower than 100% is likely to turn out unreadable.

So what's a designer to do? Always using a font-size of 100% also severely limits your typo options. IMHO it's better to have a fixed font size, especially if you have a fixed layout. That sets a predictable standard that visitors THEN can adapt by changing the zoom - be it page or text zoom.

Zoltan Hawryluk

comment number
date
March 29, 2010 20:13

This is an excellent article that describing the pros and cons of em design and how compelling the pros are. Definitely will be citing this article whenever I am questioned (especially by print designers) about why I use ems instead of pixels.

Free

comment number
date
April 20, 2010 21:14

As Bobby Jack mentioned, this theory doesn't take into account anyone that has trouble reading screen and has their default font size set to a more comfortable size, say 24px. For them setting the font to 12px makes the text completely illegible by default, sure they can zoom in, but as a designer that cares about accessibility, why not keep using ems so they can read the page by default.

If you set the to 62.5% and then use 1.2em for the body text your user above with a default size of 24 will have a body text size of 18px rather than 12px. Sure, it's still smaller than what they've chosen, but it's a lot better than 12px.

If you think the default font size isn't used much, start hanging out with older people and you'll be surprised.

Accessibility is about making it easy for your user, not going backwards, just because you're too lazy to use a calculator or add a bit extra css.

fast food

comment number
date
June 10, 2010 16:22

Seriously. Thank you, free. Usability is becoming such a big issue. Take the whole html5 versus flash war. Anything you can do, even if it takes time, to service your reader, is absolutely the most important thing you can do.

SpaceJogger

comment number
date
November 12, 2010 18:07

@Free, So if the user wants to view fonts at 24px they still have to zoom, even with your attempt at using em to accommodate them. I don't really see how using em is better than px if the user still has to zoom to achieve their desired font size.

Bybe

comment number
date
April 07, 2012 01:00

The screen resolution is still a problem even 2 years later.. :|

* required fields

Leave your data
Leave a comment