font-family accepts a comma-separated list, called a font stack, and the browser uses the first font in the list that's actually available on the user's system or loaded via @font-face, falling back to the next one if it isn't — the list should always end with a generic family keyword, like sans-serif, serif, or monospace, guaranteeing some reasonable font renders even if every named font in the stack fails to load. Font names containing spaces, like 'Times New Roman', need to be wrapped in quotes, though quoting is optional for single-word names.
1Understanding Font-family
font-family accepts a comma-separated list, called a font stack, and the browser uses the first font in the list that's actually available on the user's system or loaded via @font-face, falling back to the next one if it isn't — the list should always end with a generic family keyword, like sans-serif, serif, or monospace, guaranteeing some reasonable font renders even if every named font in the stack fails to load. Font names containing spaces, like 'Times New Roman', need to be wrapped in quotes, though quoting is optional for single-word names.
Always end a font-family list with a generic family keyword, like sans-serif or serif — without it, if every named font in the stack fails to load, the browser falls back to its own unpredictable default rather than at least matching the intended general style.
body {
font-family: "Helvetica Neue", Arial, sans-serif;
}2Practical Example
Here is a real-world application of Font-family showing how it is used in production CSS code.
code {
font-family: "Courier New", monospace;
}3Best Practices
Follow these guidelines when working with Font-family:
1. Always include a generic family keyword, like sans-serif or serif, as the final fallback in a font-family list
2. Quote font names containing spaces, like "Times New Roman", since unquoted multi-word names would otherwise be misparsed as multiple separate font names
3. List web-safe or explicitly loaded fonts first, with progressively more general fallbacks afterward, so text remains reasonably styled even if a specific font fails to load
Tip: Always end a font-family list with a generic family keyword, like sans-serif or serif — without it, if every named font in the stack fails to load, the browser falls back to its own unpredictable default rather than at least matching the intended general style.
body {
font-family: "Helvetica Neue", Arial, sans-serif;
}