"Ensure text remains visible during webfont load" is a performance warning that appears when your page hides text until a custom font has downloaded. On a slow connection, visitors stare at a blank area where your heading should be, sometimes for several seconds. This is called a flash of invisible text (FOIT). The fix is mostly one CSS property, font-display, plus a few changes to how fonts are loaded so the swap is quick and does not shift the layout.
Why Text Goes Invisible
When a browser needs a web font that is not downloaded yet, most browsers hide the text for up to about three seconds while they wait, then fall back to a system font. The font-display descriptor in @font-face controls this behavior:
| font-display value | What happens | Good for |
|---|---|---|
auto / block | Text hidden for up to about 3 seconds, then fallback | Icon fonts only |
swap | Fallback text shows at once, swaps when the font arrives | Most body and heading text |
fallback | Very short hidden period, short window to swap, otherwise keeps the fallback | Body text where late swaps are distracting |
optional | Uses the font only if it is ready almost immediately | Best for avoiding layout shift on repeat visits |
Step 1: Add font-display: swap
Google Fonts: add &display=swap to the stylesheet URL. Recent Google Fonts embed codes include it already, but older themes often do not.
If you use a CSS framework or theme that loads fonts for you, search the built CSS for @font-face rules without font-display. Icon fonts are the one case where block can make sense, because showing fallback letters in place of icons looks broken.
Step 2: Preload the One or Two Fonts You Need First
Preloading tells the browser to start downloading the font before it finds it in the CSS, so the swap happens sooner. Preload only the font used above the fold, usually the main text or heading font. Preloading many fonts competes with the hero image and can make LCP worse. The crossorigin attribute is required for fonts, even on your own domain.
Step 3: Load Fewer and Smaller Font Files
- Use WOFF2 only. Every current browser supports it, and it is the smallest format.
- Use a variable font instead of separate files for each weight.
- Subset to the character sets you use, such as Latin only.
- Self-host instead of loading from a third-party domain, which avoids an extra connection.
- Drop unused weights and styles. Many sites load six or eight font files and use three.
Step 4: Stop the Swap From Shifting the Layout
With font-display: swap, text appears immediately in a fallback font and then switches. If the two fonts have different widths and heights, the text reflows and pushes content around, which counts toward Cumulative Layout Shift. Match the fallback to the web font with metric overrides:
Next.js next/font generates this fallback for you. Tools such as Fontaine or Capsize calculate the values for other setups. See how to fix CLS for other causes of layout shift.
Step 5: Check the Result
Run a website audit to confirm the "ensure text remains visible during webfont load" warning is gone and that LCP and CLS did not get worse. If your site's code is on GitHub and you have connected the repository, the audit can find the file that loads the font, add font-display: swap to @font-face rules or display: "swap" to next/font calls, and open a pull request for you to review. For the related warnings, see how to fix render-blocking resources and how to fix LCP.