The font-display Property Overview
You'll learn: How the font-display CSS property lets you control what users see while web fonts are downloading.
What Is font-display?
When you use custom web fonts, there's always a delay between when the browser requests the font file and when it finishes downloading. The font-display property tells the browser what to show during that wait. Should it show invisible text? Show a fallback font immediately? Wait a bit, then switch?
Think of it like ordering a custom meal at a restaurant. Do you want to sit staring at an empty plate until it arrives (block), get a quick appetizer right away (swap), or receive a temporary substitute dish that gets replaced when yours is ready (fallback or optional)?
The Five Values
You apply font-display inside your @font-face rule:
@font-face {
font-family: 'MyCustomFont';
src: url('font.woff2') format('woff2');
font-display: swap; /* the key property */
}
The five possible values are:
auto- Browser decides (usually similar toblock)block- Brief invisible period, then swap (causes FOIT)swap- Show fallback immediately, swap when ready (causes FOUT)fallback- Very brief invisible period, then fallback, only swap if font loads quicklyoptional- Let the browser decide based on connection speed
Each value balances text visibility against visual consistency differently, addressing the FOIT (Flash of Invisible Text) and FOUT (Flash of Unstyled Text) problems you learned about previously.
Key Takeaway: The font-display property gives you control over font rendering behavior during loading, letting you choose between showing text immediately versus waiting for your custom font to arrive.