XML technologies / CSS / Advanced websites with CSS / Using fonts with CSS / Standard and nonstandard fonts / Defining font lists

(Excerpt from “CSS − Advanced websites with Cascading Stylesheets” by Rachel Andrew & Dan Shafer)

Remember that a list of alternative typefaces simply names the fonts in sequence, separated by commas. Font names containing spaces are enclosed in double or single quotation marks.

We have also seen how a browser processes a font list from left to right. As explained in the section on the property font-family, the browser takes the first font in the list and looks for it on the user’s system. If found, it uses it; otherwise, it proceeds to the next font. More precisely, the browser searches the operating system’s font directory for the family you specified. Some applications install their own fonts in application-specific directories, but these are not available to the browser.

Processing the list from left to right gives rise to two basic rules. First, list specific fonts first and general fonts last. Second, always end with a generic font category (serif, sans-serif or monospace) rather than a particular font family. This preserves the basic appearance even if the browser finds none of the previously listed fonts.

Also remember not to use several generic font categories in one CSS rule. Choose one category, then list one or more fonts in the order in which they should be applied, always ending with a generic font.

The following three CSS style rules are typical examples of alternative typeface definitions, ordered from specific to general:

p {
  font-family : "Courier New", Courier, monospace;
}

p {
  font-family : "Times New Roman", Times, serif;
}

p {
  font-family : Helvetica, Arial, sans-serif;
}

As you can see, each rule defines only one font category; any other approach would not make sense for consistent typography. The desired specific font comes first, a widespread alternative second, and the generic category last.

  

 

 

 

back to top