In the last exercise, you made the about page fit a phone’s screen. The garden’s text still uses fonts you chose before this course. On the events pages, the body has font-family: system-ui, sans-serif, and the headings have Georgia, serif. You know each value is a fallback list, but which font does a visitor actually get?
In this lesson, you’ll predict which font a visitor sees from a list of fonts and end every list in a way that always works. You’ll also choose a weight and a style and check in DevTools which font the browser really drew.
Walk Down a Font Stack
You choose the fonts, but the visitor’s device draws the text, and it can only use the fonts it has. Windows, macOS, Android, and Linux each come with different fonts installed. So a font-family value is a list of choices, called a font stack. The browser reads it from left to right and uses the first font it can find.
Open events/upcoming.html in your preview. The site’s style.css at the root holds the font token and the body’s text styles for the other pages, but this page links only the practice stylesheet, events/events.css. Its headings get their font from a rule you wrote there when you first styled the events page. If your events.css doesn’t have it, add it at the end of the file:
events/events.css
h1,
h2 {
font-family: Georgia, serif;
}
Georgia is a font name. Windows and macOS include it, but many Linux computers and some Android phones don’t. The last entry, serif, isn’t a font at all. It’s a generic family, a keyword that tells the browser to use whatever serif font it has. A generic family always resolves to some font, so it’s the one entry that can’t fail.
There are four generic families worth knowing. The serif keyword gives letters with small strokes at their ends, and sans-serif gives letters without them. The monospace keyword gives letters that all take the same width, as code does. And system-ui gives the font that the operating system uses for its own menus and dialogs, such as Segoe UI on Windows.