font-display: swap in CSS (Prevent Invisible Text)
Font loading without invisible text
Custom fonts used to cause a flash of invisible text (FOIT) while they downloaded. font-display: swap shows the fallback right away, then swaps when the font is ready.
The old hack vs the modern fix
View demo@font-face {
font-family: "MyFont";
src: url("MyFont.woff2");
}@font-face {
font-family: "MyFont";
src: url("MyFont.woff2");
font-display: swap;
}Font display browser support
Live demo
Why the modern way wins
No FOIT
Users see fallback text right away instead of blank space while the font downloads.
One line
Add font-display: swap to your existing @font-face. No JS or loading strategy needed.
Other options
optional shows the fallback after about 100ms and only uses the font if it is ready by then. block hides text for up to about 3s. swap is the safe default.
- Behavior
- Swap
- Fallback first, then custom font
- Old Approach
- Default (block)
- Invisible text until load
- Modern Approach
- font-display: swap
- Text visible immediately
How it works
Without font-display, the browser uses a default behavior that often hides text for a few seconds while the custom font loads. That is the flash of invisible text (FOIT). Users on slow connections see a blank area until the font file arrives.
Adding font-display: swap to your @font-face tells the browser to show the fallback font immediately and swap to the custom font when it is ready. Users can read right away; they may see a brief reflow when the font loads, but that is usually better than invisible text. Use it on every @font-face unless you have a reason to use optional or block.