Font Families: Generic Families, Font Stacks and System Fonts
Choosing typefaces with font-family: how stacks fall back character by character, when names need quotes, the generic families including system-ui, ui-monospace and math, system font stacks, the monospace size quirk, and how lang affects fonts.
kvi5hnuCode Sprout team member7 min readOn this page
font-family chooses the typeface. It takes a list, called a font stack, because you can't be sure any one font is available: the browser uses the first one it can, and the last entry is always a generic family that every browser can provide.
body { font-family: Inter, "Helvetica Neue", Arial, sans-serif; }
code { font-family: ui-monospace, "Cascadia Code", Menlo, Consolas, monospace; }
font-family is inherited, so setting it on body or :root styles the whole page, apart from form controls, which have their own fonts by default (article 102 covers styling them).
How the stack falls back

Fallback works per character, not per element. For each character, the browser uses the first family in the list that is available and has a glyph for it. So a Latin-only web font followed by a Japanese font draws English in the first and Japanese in the second. If no listed family has the character, the browser tries the generic family, and then any installed font that has it. That's how emoji and rare symbols still appear, though possibly in a mismatched style.
Two consequences:
- Order matters: put the font you want first, then close substitutes, then the generic.
- Always end with a generic family. Without one, characters that the listed fonts lack fall back to the browser's default font, usually a serif.
Writing family names
Family names are case-insensitive. Quotes are optional for most names, even with spaces, but required when:
- the name is the same as a generic family or a CSS keyword, like
"serif","inherit"or"initial"; - the name contains characters other than letters, digits, hyphens and underscores, or a part starts with a digit, like
"Font Awesome 6 Free".
Quote any name with spaces to be safe; browsers serialize them that way. Tested in Chrome: font-family: Open Sans, serif reads back as "Open Sans", serif.
Never quote generic names: a quoted "sans-serif" means a font literally called sans-serif. Tested in Chrome with the 16px text "The quick brown fox jumps over": in "sans-serif" it was 210.2px wide, exactly as wide as in serif, because no font has that name and the browser fell back to its default serif; in unquoted sans-serif it was 225.9px wide.
Generic families
| Generic | What it maps to | Support |
|---|---|---|
serif | a font with serifs, like Times or Georgia | all |
sans-serif | a font without serifs, like Helvetica or Arial | all |
monospace | every character the same width, for code | all |
cursive | handwriting or script style | all |
fantasy | decorative; unpredictable, so rarely useful | all |
system-ui | the operating system's interface font: San Francisco on Apple devices, Segoe UI on Windows, Roboto on Android | all |
ui-serif, ui-sans-serif, ui-monospace, ui-rounded | the system's interface fonts of each style, like SF Mono and SF Pro Rounded | Safari only |
math | a font for mathematical formulas, with the needed glyphs and tables | Chrome 109, Firefox 149, Safari 26.2 |
emoji, fangsong | emoji, and a Chinese style between serif and script | specified; limited support |
Generics that a browser doesn't support are treated like an unknown family name and skipped, so it's safe to list ui-monospace before monospace: tested in Chrome, ui-monospace alone falls back to the default font.
What the generics map to depends on the operating system and on the user's settings: many browsers let people choose their default serif, sans-serif and monospace fonts. So serif on its own won't look the same everywhere, but it always looks like a serif.
System font stacks
Using the fonts already on the device costs no download and matches the platform's look:
:root { font-family: system-ui, sans-serif; }
Older stacks listed each platform's font by name, like -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, …; system-ui replaces that in all current browsers.
system-ui has a drawback: on some systems it picks a font for the operating system's language, which may not suit the page's language. For text-heavy pages, a named stack of widely installed fonts in the same style gives a more consistent result:
/* similar humanist sans-serif fonts on each system */
.prose { font-family: Seravek, "Gill Sans Nova", Ubuntu, Calibri, "DejaVu Sans", source-sans-pro, sans-serif; }
/* similar old-style serifs */
.article { font-family: "Iowan Old Style", "Palatino Linotype", "URW Palladio L", P052, serif; }
/* code */
code, pre, kbd, samp { font-family: ui-monospace, "SF Mono", "Cascadia Code", "Roboto Mono", Menlo, Consolas, monospace; }
Choose fonts that are similar in size and shape to each other, so the layout doesn't shift much from one system to the next.
The monospace size quirk
Browsers give font-family: monospace alone a smaller default size, 13px instead of 16px, a legacy behavior. Tested in Chrome: monospace alone was 13px; monospace, monospace, ui-monospace, monospace and Menlo, monospace were all 16px. Listing any other family first, or setting an explicit font-size, avoids it. This is why some resets write font-family: monospace, monospace.

The generics are only names for whatever the browser and system map them to, so cursive and fantasy look different on every platform, and ui-rounded falls back when no rounded system font exists. The bottom row is the quirk above, measured in a page with no font sizes set.
Language and fonts
The HTML lang attribute affects font choice. Chinese, Japanese and Korean share many characters but draw them differently, and browsers pick a generic font for the language: <p lang="ja"> gets a Japanese font, <p lang="zh-Hans"> a Simplified Chinese one. Always set lang on <html>, and on passages in other languages.
You can also target languages in CSS:
:lang(ja) { font-family: "Hiragino Sans", "Noto Sans JP", "Yu Gothic", sans-serif; }
body { font: 0.85rem system-ui, sans-serif; margin: 1rem; }
select { font: inherit; max-inline-size: 100%; }
.sample { margin-top: 0.75rem; padding: 0.75rem; border-radius: 8px; background: #f4efe6; }
.sample p { margin: 0 0 0.5rem; font-size: 1rem; line-height: 1.5; }
.sample .big { font-size: 1.6rem; line-height: 1.1; color: #8a3b12; }
.used { color: #555; font-family: ui-monospace, Menlo, monospace; font-size: 0.75rem; }
Try NoSuchFont: with no generic at the end, the text falls back to the browser's default font. And notice how cursive and fantasy vary between systems.
What's current
system-uiworks in all browsers; theui-*generics only in Safari.mathis in all current browsers (Safari 26.2).font-familylists can include the font's local name, or web fonts loaded with@font-face(article 83).- Fallback fonts can be adjusted to match a web font's size with
size-adjustand other@font-facedescriptors (article 84).
Common questions
Do I need quotes around font names? Only for names that match a keyword or contain unusual characters, but quoting names with spaces is a good habit. Never quote generic families.
Why did my text change to a serif font? None of the listed fonts was available and the stack didn't end with a generic family, so the browser used its default.
Why is my code text smaller than expected?
font-family: monospace alone gets a 13px default. Add another family before it, or set font-size.
Is system-ui a good default?
For interfaces, yes. For long text in a specific language, a named stack can be more predictable.
Summary
font-familytakes a stack; the browser uses, for each character, the first available family that has a glyph for it.- End every stack with a generic family, and never quote generics.
- Quotes are required for names that clash with keywords or contain unusual characters.
system-uigives the platform font with no download;ui-*generics are Safari-only, so list a fallback after them.monospacealone gets a 13px default size; list another family first.- Set
langso the browser picks the right fonts for each language.
Practice questions
Write a font stack for code that prefers the system's monospace font and always ends at the right generic.
Answer
code { font-family: ui-monospace, Menlo, Consolas, "Liberation Mono", monospace; }
What's wrong with this declaration?
h1 { font-family: "Playfair Display", "serif"; }
Answer
"serif" is quoted, so it refers to a font named serif rather than the generic family. Write serif without quotes.
A page uses font-family: Inter, sans-serif, with Inter loaded as a Latin-only web font. How are Greek words on the page drawn?
Answer
In the generic sans-serif font, or another installed font that has Greek glyphs: fallback works per character, so the Latin text uses Inter and the Greek characters fall through to the next family.
Why does <code> with font-family: monospace look smaller than <code> with font-family: Menlo, monospace?
Answer
Browsers give monospace alone a 13px default size instead of 16px. Any other family in the list removes that quirk.
Previous: Print Styles: @media print, @page, Page Breaks and Margin Boxes
Next: Web Fonts: @font-face, Formats, unicode-range and Multiple Styles

More in CSS Course
Quiz: CSS Delicate Details
Twenty-five questions on the edge cases that surprise experienced developers: invalid custom properties, shorthands that reset values, layer order with !important, containing blocks, margin collapsing, specificity of :is() and :where(), intrinsic minimum sizes, and more, each checked in Chrome.
Quiz: CSS Interview Questions
Thirty front-end interview questions: cascade, specificity and layers, box model and margin collapsing, stacking contexts, positioning, flexbox and grid, responsive design, custom properties, performance, accessibility, modern selectors and architecture.
Quiz: CSS Course Final Exam
Thirty questions across the whole CSS course: syntax and error handling, selectors, the cascade and layers, values and units, color, the box model, backgrounds, positioning, flexbox, grid, responsive design, typography, generated content, effects, transforms, motion and architecture.
Quiz: CSS Architecture, Tooling and Debugging (CSS Part 17)
Twenty questions on modular CSS and BEM, layering a stylesheet, design tokens and theming, pattern libraries and safe refactoring, preprocessors and build tools, the at-rules reference, and debugging common CSS problems.
Discussion
Sign in to ask a question or share what you learned.