liveBook · Manning

Font-family property

As explained in Web Design Playground

A CSS property that specifies the preferred font family or ordered list of font families for text rendering.

The CSS font-family property chooses the typeface used to draw an element’s text. Think of it as giving text a wardrobe: a clean sans-serif outfit for body copy, a traditional serif look for a large heading, or monospace for code. A typeface is the design itself; size, weight, and style further shape how that design appears. section 4.2 section 4.32

Serif —A serif (rhymes with sheriff) typeface contains fine cross strokes (called feet) at the extremities of each character. These subtle appendages give the typeface a traditional, classy look, but they can get lost when displayed on a screen at small sizes. 04_table_01.png
Sans serif —A sans-serif typeface doesn't contain cross strokes on the extremities of characters. These typefaces usually have a clean, modern look that’s well suited to screen text, particularly at small sizes. 04_table_02.png
Monospace —A monospace typeface (also called a fixed-width typeface) uses the same amount of space for each character, so skinny letters such as i and l take up as much space as wider letters such as m and w. 04_table_03.png
Cursive —The cursive typefaces are designed to resemble handwritten pen or brush writing. 04_table_04.png
Fantasy —Fantasy typefaces usually are fanciful designs that have some extreme elements (such as being extra-thick). 04_table_05.png

Typeface families are broad visual categories. Serif has small finishing strokes; sans serif is clean and screen-friendly; monospace gives every character equal width; cursive resembles handwriting; fantasy is for special effects. section 4.2

Start simply with a generic family. Modern browsers implement five generic choices: serif, sans-serif, monospace, cursive, and fantasy. Generic families are useful when you want a dependable style without asking for one particular installed typeface. section 4.3 section 4.32

Choose heading and paragraph families

Use a selector, then give font-family a value: h3 { font-family: sans-serif; } p { font-family: serif; } Here, h3 text receives the sans-serif generic family and paragraph text receives the serif generic family. On screens, serif is suited to larger text such as headings, while sans serif works well for body text. section 4.2 section 4.3

You can also name a system font installed on a visitor’s computer. Put quotation marks around a name containing spaces, numbers, or punctuation other than a hyphen. Capitalizing font names is optional, but makes the rule easier to read. section 4.6

Add a fallback stack

font-family: "Times New Roman", Georgia, serif; A comma-separated list is a font stack. The browser tries each family from left to right and uses the first installed system font. Finish with a similar generic family, because visitors may not have either named font. section 4.6 section 18.2

font-family: "League Spartan", Futura, Tahoma, sans-serif; 

A stack can move from a preferred font to close alternatives and end with a matching generic family: "League Spartan", Futura, Tahoma, sans-serif. section 18.2

Web fonts work with the same property after the font is made available. A hosted-font service can provide a link that loads a font, then a rule such as p { font-family: Lato, sans-serif; } applies it. Self-hosted fonts use @font-face to assign a family name, which font-family can then use. Load only the font styles you need, since extra fonts can slow page loading. section 18.6 section 18.9

Play with one heading, one paragraph, and one code-like list: give each an appropriate generic family first, then replace one generic value with a small font stack. Keep the generic fallback at the end so the text still has a sensible look when preferred fonts are unavailable. section 4.2 section 18.2

How Web Design Playground covers it

How deep it goes
Explains generic fonts, system-font syntax, ordered stacks, hosted fonts, and @font-face application without detailing font-file creation.
Examples
Uses h3 and p generic-family rules, a Times New Roman–Georgia–serif stack, Lato hosted-font CSS, and Bree Serif @font-face CSS.
What it assumes
Introduces generic family selection directly while assuming familiarity with CSS rules and HTML elements such as div, h3, p, and ul.
What you can do after
Apply it via CSS to choose generic, installed, hosted, or self-hosted typefaces with sensible fallbacks.
How it connects
Connects typeface categories, generic fonts, system fonts, font stacks, web fonts, and @font-face.

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. The section links point to the parts of the book it draws on.