font-display in @font-face Rules
You'll learn exactly where and how to place the font-display property inside your font declarations to control loading behavior on a per-font basis.
The Syntax and Placement
You've learned about the different font-display strategies (block, swap, fallback, optional, and auto). Now it's time to see where this property actually lives in your CSS code.
The font-display property goes inside your @font-face declaration, right alongside other font descriptors like src, font-family, and font-weight:
@font-face {
font-family: 'MyCustomFont';
src: url('/fonts/mycustomfont.woff2') format('woff2');
font-weight: 400;
font-style: normal;
font-display: swap;
}
Per-Font Customization
Here's the powerful part: each @font-face rule can have its own font-display value. This means you can apply different loading strategies to different font files.
For example, you might use swap for body text (to ensure readability quickly) but optional for decorative headings (where the fallback is acceptable):
@font-face {
font-family: 'BodyFont';
src: url('/fonts/body.woff2') format('woff2');
font-display: swap; /* Critical text */
}
@font-face {
font-family: 'FancyHeadline';
src: url('/fonts/fancy.woff2') format('woff2');
font-display: optional; /* Nice-to-have */
}
This granular control lets you balance performance and design priorities across your typography system.
Think of It Like a Recipe Card
Each @font-face is like a recipe card for a specific font file. The font-display property is one ingredient in that recipe—you're telling the browser exactly how to serve that particular font to users.
Key Takeaway: The font-display property goes inside individual @font-face rules, allowing you to customize loading behavior per font file for maximum performance and design flexibility.