Name

font-family

Values:

family name , generic family name

Example:

P { font-family: "Trebuchet MS", Verdana, sans-serif }

Applies to:

All elements

Inherited:

Yes

You can specify any font (or list of fonts, separated by commas) in the font-family property. Bear in mind, however, that the font needs to be present on the user’s machine in order to display, so it is safest to stick with common fonts.

You may (and it is advisable) include a generic font family as the last option in your list so that if the specific fonts are not found, a font that matches the general style of your choices will be substituted. The five possible values are:

  • serif (e.g., Times)

  • sans-serif (e.g., Helvetica or Arial)

  • monospaced (e.g., Courier or New Courier)

  • cursive (e.g., Zapf-Chancery)

  • fantasy (e.g., Western, Impact, or some display-oriented font)

Note that in the example, the first font is enclosed in quotes. Font names that contain character spaces must be enclosed in quotation marks (single or double). Generic family names must never be enclosed in quotation marks.

Get Web Design in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.