Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Typography

The font-family property

Reference for the CSS font-family property: build font stacks with fallbacks, use generic families like system-ui and monospace, and quote names correctly.

The font-family property gives the browser an ordered list of fonts to use for text. The browser looks at the first family, and if the font is not available (or does not contain a needed character), it moves on down the list. This list is called a font stack.

Each entry is either a specific family name (such as Georgia) or a generic family (such as serif). Always end the list with a generic family, so the browser has something sensible to fall back to.

CSS
body { font-family: "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
code { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; }

Try it

Generic families and a fallback stack

The exact look of each generic family depends on the fonts installed on the visitor's device.

Syntax

CSS
font-family: [ <family-name> | <generic-family> ]#;
  • Initial value: depends on the user agent (usually a serif font such as Times)
  • Applies to: all elements and text
  • Inherited: yes
  • Animatable: no (discrete)
  • Computed value: as specified

Values

Value Description
<family-name> The name of a specific font, such as Georgia or "Helvetica Neue". Names with spaces, digits or punctuation should be quoted.
serif Fonts with small strokes at letter ends, like a typical book font.
sans-serif Fonts without those strokes.
monospace Fonts where every character has the same width.
cursive Handwriting-style fonts.
fantasy Decorative display fonts. Rarely a good choice.
system-ui The default user-interface font of the operating system.
ui-serif, ui-sans-serif, ui-monospace, ui-rounded The system's own serif, sans-serif, monospace and rounded UI fonts, where available.
math, emoji, fangsong Fonts for mathematical expressions, emoji, and a Chinese typographic style.

Usage notes

  • Never quote generic names. "serif" in quotes is treated as a font named serif, not the generic family. serif without quotes is the generic one.
  • Quote names when in doubt. Quotes are required for names that are not valid identifiers (names with digits or special characters) and recommended for any name with spaces.
  • Fallback is per character. If the first font lacks a glyph, the browser uses the next font that has it, only for that character.
  • Custom fonts. Fonts loaded with @font-face are used by name in the same list. Always list fallbacks in case the file fails to load.
  • System stacks are fast. system-ui and friends need no download, so there is no flash of unstyled text and no layout shift.
  • Case does not matter in font names, but spelling and spaces do.
  • Match metrics when possible. If your web font and fallback differ in size, text jumps when the font loads. See font-size-adjust.

Browser support

Supported in every browser. The newer generics (ui-serif, ui-rounded and others) are not available everywhere, which is harmless as long as a stack continues with older names.