Course contentsShow
← Web Development
Lesson 1274 of 2,98223. Web Font OptimizationFree lesson

font-display: swap Strategy

Master the swap value for immediate text visibility with fallback fonts, best for body text and content-first sites.

What You'll Learn

You'll discover how font-display: swap ensures text appears immediately using a fallback font while your web fonts download in the background.

The Swap Strategy Explained

With font-display: swap, the browser takes a "content-first" approach: it shows your text immediately using a fallback system font, then swaps in your custom web font once it's ready. There's no blocking period where text stays invisible.

Think of it like this: You're at a restaurant that just ran out of your favorite plate. Instead of making you wait hungry, they serve you a similar dish right away, then swap it out when your original order is ready. You get fed immediately, even if the presentation changes slightly.

When you declare:

@font-face {
  font-family: 'CustomFont';
  src: url('customfont.woff2') format('woff2');
  font-display: swap;
}

The browser will:

  1. Show text instantly using Arial, Times, or whatever fallback you specified in your font-family stack
  2. Download your custom font in the background
  3. Swap in the custom font as soon as it arrives (with no time limit)

When to Use Swap

This strategy is ideal for:

  • Body text and content-heavy sites where readability matters most
  • News sites, blogs, and documentation where users need information fast
  • Any situation where invisible text is worse than a brief font change

The tradeoff? Users may see a quick visual shift (often called a "flash of unstyled text" or FOUT) when the swap happens. But they can read your content right away, which is usually more important than perfect typography.

Key Takeaway: font-display: swap prioritizes immediate text visibility over visual consistency, making it the best choice for content-first websites where readable text matters more than preventing font swaps.