Chapter 2. Styling Text

In This Chapter

  • Introducing fonts and typefaces

  • Specifying the font family

  • Determining font size

  • Understanding CSS measurement units

  • Managing other font characteristics

  • Using the font rule to simplify font styles

Web pages are still primarily a text-based media, so you'll want to add some formatting capabilities. XHTML doesn't do any meaningful text formatting on its own, but CSS adds a wide range of tools for choosing the typeface, font size, decorations, alignment, and much more. In this chapter, you discover how to manage text the CSS way.


A bit of semantics is in order. The thing most people dub a font is more properly a typeface. Technically, a font is a particular typeface at a particular size with a specific set of decorations (underlining, italic, and so on). The distinction is honestly not that important in a digital setting. You don't explicitly set the font in CSS. You determine the font family (which is essentially a typeface), and then you modify its characteristics (creating a font as purists would think of it). Still, when I'm referring to the thing that most people call a font (a file in the operating system that describes the appearance of an alphabet set), I use the familiar term font.

Setting the Font Family

To assign a font family to part of your page, use some new CSS. Figure 2-1 illustrates a page with the heading set to Comic Sans MS.

If this page is viewed on a Windows machine, it generally displays the font correctly because Comic Sans MS ...

Get HTML, XHTML, & CSS All-in-One For Dummies®, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.