How To Size Text the Web Standards Way

This blog entry covers:
- Why it is important to use relative text sizing units (ems and percentages)
- Why NOT to use pixel units
- Why NOT to use point units
- Why NOT to use keywords
- Helpful resources
When designing web pages, you might think that choosing a font size should be amongst the easiest and quickest decisions a web designer makes: simply choose a readable pixel size and move on right? Well, that is one way to do it...but it certainly isn't the most thoughtful, adaptable and accessible. It is, for several reasons, bad practice and anyone designing a website should seriously consider getting acquainted with the relative way of sizing text. It takes more work, but it's a more efficient method that produces better results across multiple browsers and devices and allows your content to be accessible by a wider audience.
Pixels are not the only way to size text. The units available to web designers for sizing text are pixels, points, percentages, ems, and even keywords.
So which should you use?
Ems and percentages are considered the desirable units for sizing fonts using CSS because they avoid the pitfalls of pixel and point sizing (explained below), are re-sizable in all browsers that support resizing, AND are relative to a user's font size preferences.
Yeah, well, computer screens display in pixels. I love pixels. Why shouldn't I design in pixels?:
That would be lovely if everyone used the same browser, the same monitor and if we all had the same vision. We, however, don't live in that world and good design keeps functionality at the forefront. A well-designed website will allow text resizing and will do its best to look the same across different browsers, platforms, devices, etc. The proper text sizing tool in the web designer's arsenal is not the pixel, it is the em (with a little help from the %).
When it comes to text (and line-heights), our usual friend The Pixel, ignores user preferences and doesn't re-size in Internet Explorer. This makes pixel-defined text sizes a bad idea when considering accessibility issues and we must consider accessibility issues. Accessibility to equal information and services is not only a human rights issue (which is reason enough), but also about making sure your code can be adaptable to a variety of devices and applications.
The resizing issue can't be underestimated. Internet Explorer stills claims the largest audience and small text is a very real problem for countless users.
Another drawback, albeit one that I am guessing is not an issue for the majority of websites, is an inconsistency amongst browsers on how to handle non-integer pixel values (i.e. some can handle 12.5 px, while others can not). This matters if pixel-perfect sizing is desired on every major browser. I doubt designers regularly (if ever) code non-integer pixel units for text sizes, but it can accidentally happen when a pixel value is applied to a parent and a percentage or em to its child.
Ok, what about points?:
No! Don't do it! Points were not designed for screen-based design. They are a great desktop publishing unit, but not a great web design unit. When being converted to pixels, the math is extremely inconsistent amongst different browsers. It's a confusing explanation best left at: don't use points for text sizing unless you are writing a print-media style sheet.
Hm, well, that leaves keywords?:
No again and I find them too confusing to explain very well, but they offer up the same issues as points regarding consistency and control problems. For a detailed explanation by someone much better at explaining these than me, feel free to read this concise explanation.
Helpful Resources:
The Em Calculator: Converts pixel sizes into em sizes
A List Apart article: Explains how to use ems and percentages to size text using CSS