Specifying Fonts and Inheritance

16 March 2008

 

Problem

You want to set the typeface of text on a web page.

Solution

Use the font-family property:

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

}

You can specify the fonts you want the browser to render on a web page by writing a comma-delimited list for the value of the font-family property. If the browser can’t find the first font on the list, it tries to find the next font, and so on, until it finds a font.

If the font name contains spaces, enclose the name with single or double quotation marks. You can enclose all font names in quotes, regardless of whether they contain spaces, but if you do, browsers with poor CSS implementations might not render the fonts accurately.

At the end of the list of font choices, you should insert a generic font family.