Sizing Fonts
In this section, you'll learn to size fonts using the font-size property along with an absolute, relative, length, or percentage value.
Absolute and Relative Keywords
Absolute keywords size fonts based on the way that the browser computes their size. The keywords available are xx-small, x-small, small, medium, large, x-large, and xx-large. Here, I've applied an absolute keyword to paragraph text:
The medium size is typically equivalent to the browser's default size for that element. Figure 9-3 shows all the keywords as applied to default browser text.
p {font-size: medium;}
Figure 9-3. Absolute keyword sizing within a web browser.
Length Values
Length values are used with many properties. They include three relative and five absolute values. Relative values are em, ex, and px; absolute values are pt, pc, in, mm, and cm. Absolute values should not be used for the screen, although they are useful when creating print style sheets.The most commonly used length values for type on the Web are pixels and ems because, technically, they are both scalable, which is appropriate for screen. There's a major problem, however: Microsoft Internet Explorer for Windows does not scale pixels. This is a terrible oversight that has caused real problems, especially because you want to offer your vision-impaired users scalable sizing. Compare the values on the left to the values on the right, where I've bumped up the browser text (in IE, View > Text Size) from its default size of medium to larger (see Figure 9-4).
Figure 9-4. Comparing font sizes in Internet Explorer 6.0.
Percentages
Percentage values in font sizing are always relative to another value, such as a keyword or length value. So, if I set my body font size to 1em and then set my H1 header to 150%, I'll end up with a larger h1 than the body font size, which is relative to the browser default:
Percentages are particularly helpful in working around browser limitations in font sizing. The reason is that percentages are also scalable. As a result, many workarounds for the pixel problem in IE have been achieved by combining ems and percentages. Still, many designers prefer to go with pixels because of their more consistent rendering, at the cost of better accessibility.NOTEYou'll use a variety of sizing options throughout this book, to get the hang of it. For more information on font sizing problems, see Owen Briggs's article "Text Sizing," at http://www.thenoodleincident.com/tutorials/box_lesson/font/indexl.
body {font-size: 1em;}
h1 {font-size: 150%}