Font face and loading strategy
Definition and purpose
An @font-face rule defines a face that participates in font selection. It describes a family, source and characteristics; it does not apply that family to any element until a font-family declaration selects it. A local() source requests an installed face by name; a url() source requests a font resource.
Declare a fallback face
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; font: 16px sans-serif; color: #172033; background: white; } @font-face { font-family: LessonMissing; src: local("ByteMind Nonexistent Test Face 73"); font-display: swap; } #a { font-family: LessonMissing, serif; } </style> </head> <body> <p id="a">Readable fallback text</p> </body></html>The family is requested and the descriptor is swap; the deliberately missing face falls through to serif.
Syntax and mental model
font-display controls the font display periods while a face is loading. swap favors an early fallback and permits a later swap; optional gives the browser more discretion about replacing the fallback. Neither value guarantees a particular loading duration. The deliberately unavailable local face below avoids network dependencies. Inspect the rule descriptors and the fallback stack, not a claimed successful download. In a real project, use a licensed WOFF2 resource, declare its matching weight/style and verify document.fonts.load() and rendered glyph coverage.
Optional display strategy
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; font: 16px sans-serif; color: #172033; background: white; } @font-face { font-family: LessonMissing; src: local("ByteMind Nonexistent Test Face 73"); font-display: optional; } #a { font-family: LessonMissing, sans-serif; } </style> </head> <body> <p id="a">Readable fallback text</p> </body></html>The source remains unavailable; the rule requests optional display and a sans-serif fallback.
Common mistakes
Do not put font-display on a paragraph: it is an @font-face descriptor. A computed font-family list is not proof that the first face loaded or that all glyphs use it.
Practice and next steps
After trying the examples, complete the linked coding exercise and review questions. Predict the result before running your code. Prerequisite: Readable article mini-project, International component project. Next lesson: Variable fonts and font features.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Font face and loading strategy — knowledge check
Five questions on font face and loading strategy.
Where is font-display declared?
What does local() request?
What does the computed family list prove?
Why include a generic family?
What does swap allow?