liveBook · Manning

Font-family property

As explained in Web Design Playground, Second Edition

The CSS font-family property specifies the typeface or sequence of fallback typefaces used to render an element.

The CSS `font-family` property tells the browser which typeface to use for an element’s text. A typeface is the design of the letters; a font is that design at a particular size, weight, and style. You can start with a generic family, name a typeface installed on the visitor’s computer, or use a font loaded from a host. section 4.1 section 4.2 section 4.3 section 18.3

Five generic families give you a quick starting point:

  • `serif` has small finishing strokes and can work well for larger headings; `sans-serif` has a cleaner look suited to body text. section 4.1
  • `monospace` gives every character the same width, making it useful for code listings. section 4.1
  • `cursive` resembles handwriting and suits short, playful touches; `fantasy` is for a special effect. section 4.1

Start with a generic family

`h3 { font-family: sans-serif; }` gives level-three headings a sans-serif typeface, while `p { font-family: serif; }` gives paragraphs a serif one. The selectors decide which elements change; the property decides their typeface. section 4.2

Want a particular system font? List alternatives separated by commas. The browser checks them in order and uses the first one installed on the visitor’s computer. Finish with a similar generic family as a fallback: `font-family: "Times New Roman", Georgia, serif;`. Quote names containing spaces, numbers, or punctuation other than a hyphen; capitalizing system-font names also makes the CSS easier to read. section 4.3

Choose typefaces for a whole page

`body { font-family: Optima, Calibri, sans-serif; }` applies the choice to page text. Optima may be available on a Mac but not a Windows PC, so Calibri and then the generic `sans-serif` provide alternatives. A clean sans-serif also keeps a short landing page’s text from competing with its message. section 10.3

A hosted font takes one extra step: load its provider’s CSS before your own styles, then name the family in a rule such as `p { font-family: Lato, sans-serif; }`. The generic fallback covers a font file that fails to load. Add only the font styles you need—extra fonts slow page loading. section 18.3

How Web Design Playground, Second Edition covers it

How deep it goes
Works through generic families, system-font naming and ordered fallbacks, then shows how to use a hosted family.
Examples
Shows sans-serif headings, serif paragraphs, a landing-page font stack, and paragraphs styled with Google Fonts’ Lato.
What it assumes
Assumes familiarity with HTML elements and basic CSS rules while introducing generic and system font choices.
What you can do after
Operate/configure it to choose an element’s typeface and provide alternatives when a preferred font is unavailable.
How it connects
Connects typeface categories and CSS selectors with system fonts, generic fallbacks, and hosted fonts.

Also explained in

Compare how 3 books explain font-family property →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Web Design Playground, Second Edition. The section links point to the parts of the book it draws on.