Best Division

Spread Your Knowledge

  • All topics
  • About us
  • Contact us
  • Privacy policy
  • Terms of service
  • Copyright
  • Facebook
  • Twitter
  • Instagram
  • Youtube
  • LinkedIn
  • Pinterest
  • Github
  • Tumblr

© 2026 Best Division

How does font-display prevent invisible text while fonts load?

CSS
Jayant Kumar
Jayant Kumar@jayantkumar314
PublishedDec 6, 2026
5 min read

The font-display descriptor tells the browser what to show while a web font is still downloading. With font-display: swap, the browser draws the text immediately in a fallback font and swaps in the web font as soon as it arrives, so readers never stare at invisible text. That is why css font-display swap is the usual choice for body text.

Without it, many browsers hide text for up to about three seconds (the "flash of invisible text", or FOIT). This guide explains the loading timeline, each font-display value, how to pick one, and how to reduce the layout shift that swapping can cause.

Table of Contents

  • The font loading timeline and FOIT
  • Setting font-display in @font-face
  • The five font-display values
  • Choosing the right value
  • Reducing layout shift when fonts swap
  • Preloading the critical font
  • Frequently Asked Questions
    • What is the difference between swap and fallback?
    • Does font-display work with Google Fonts?
    • Why does my text jump when the font loads?
    • Should I use optional for body text?
  • Summary
  • Related Articles

The font loading timeline and FOIT

When the browser finds text that needs a web font, it starts downloading the font file. During the wait it moves through up to three phases, called periods:

  1. Block period: the text is invisible (or drawn with an invisible fallback).
  2. Swap period: the fallback font is shown, and the web font replaces it when it arrives.
  3. Failure period: the font is treated as failed and the fallback stays.

The font-display value decides how long each period lasts. The default value, auto, lets the browser choose, and most browsers use a block period of around three seconds. On a slow connection that means a blank headline, which hurts both readers and perceived speed.

Setting font-display in @font-face

font-display is a descriptor inside @font-face, not a property you set on elements:

css

If you load fonts from Google Fonts, adding &display=swap to the stylesheet URL makes Google emit this descriptor for you.

The five font-display values

ValueBlock periodSwap periodTypical use
autoBrowser decidesBrowser decidesRarely best; avoid
blockShort (about 3s)InfiniteIcon fonts, brand text that must not show a fallback
swapVery short (about 100ms or less)InfiniteBody text and headings
fallbackVery short (about 100ms)Short (about 3s)Text where a late swap would be jarring
optionalVery short (about 100ms)NoneNon-critical fonts; the browser may skip the download

The exact times are recommendations in the CSS Fonts specification, and browsers may tune them. What matters is the shape: swap always ends up using the web font, fallback gives up on a swap after a few seconds, and optional only uses the font if it is already available quickly.

Choosing the right value

  • Use swap for most text. Content shows at once and the brand font appears when ready.
  • Use fallback when the layout jump from a late swap would hurt, for example a long article already being read.
  • Use optional for decorative fonts. On the first visit the page may stay in the fallback, and later visits use the cached font with no swap at all.
  • Use block only when a fallback would be wrong, such as an icon font where the fallback shows meaningless letters. Modern projects usually replace icon fonts with SVG.

Reducing layout shift when fonts swap

A swap can reflow text if the fallback and web font have different widths and heights. That shows up as cumulative layout shift (CLS). You can reduce it by adjusting the fallback to match the web font with descriptors in a second @font-face:

css

The percentages here are examples; tools such as the font metrics calculators in popular frameworks compute the right numbers for each font pair. Measure the result, because the correct values depend on the specific fonts.

Preloading the critical font

Pair font-display with a preload for the one font used above the fold, so the download starts earlier:

html

The crossorigin attribute is required even for same-origin fonts, because fonts are fetched in anonymous CORS mode. Preload only one or two files; preloading everything competes with other critical resources.

Frequently Asked Questions

What is the difference between swap and fallback?

Both show fallback text quickly. swap will replace it whenever the font arrives, however late. fallback only swaps if the font arrives within a short window of about three seconds, otherwise the fallback stays.

Does font-display work with Google Fonts?

Yes. Add display=swap (or fallback, optional, block) to the css2 URL and Google writes the matching font-display into its @font-face rules.

Why does my text jump when the font loads?

The fallback and web font have different metrics. Pick a similar fallback and use size-adjust and the override descriptors to match them.

Should I use optional for body text?

Only if you accept that some first-time visitors will see the fallback. It gives the best stability, but the brand font may not appear on the first page view.

Summary

Set font-display inside @font-face so text is never invisible while a web font loads. Use swap for most text, fallback or optional when stability matters more than the exact font, and block rarely. Preload the critical file and tune fallback metrics to limit layout shift.

Related Articles

  • How do you use Google Fonts on a website with CSS?
  • What are variable fonts and how do you use them in CSS?
  • Learn CSS: Complete Study Roadmap from Beginner to Advanced
Share

Similar posts

  • How do you use Google Fonts on a website with CSS?
  • How Do You Load Custom Web Fonts With CSS @font-face?
  • How Do font-weight and font-style Work in CSS?
  • How Do You Change Fonts With CSS font-family and Font Stacks?
  • How Do You Use CSS filters Like blur and grayscale?
  • How Does the CSS opacity Property Work?
  • How Do You Add Shadows to Elements With CSS box-shadow?
  • How do you create rounded corners with border-radius in CSS?