How to Keep Text Visible During Webfont Load in WordPress

admin
No comments on How to Keep Text Visible During Webfont Load in WordPress

If you’ve run your site through PageSpeed Insights, you may see a recommendation to ensure text remains visible during webfont load. The fix involves setting font-display to swap or optional via a plugin, cache tool, or by editing your font CSS. Preloading key fonts can further eliminate layout shifts.

FOIT vs. FOUT

When custom fonts load, browsers either hide text or show a fallback font. Understanding these behaviors helps you choose the right strategy:

  • FOIT (Flash of Invisible Text): No fallback font is shown, so text remains invisible until the custom font loads (penalized by PageSpeed Insights).
  • FOUT (Flash of Unstyled Text): A fallback font is displayed first; when the custom font loads, a layout shift occurs if font sizes differ.

FOIT vs FOUT

Use Font-Display: Swap or Optional

Edit your @font-face rules to include font-display: swap; or font-display: optional;. Many performance plugins also offer settings to apply this automatically:

  • WP Rocket: adds swap on installation.
  • Perfmatters: choose display swap under Fonts.
  • FlyingPress: enable display fallback fonts.
  • Or use dedicated plugins like Swap Google Fonts Display or OMGF.

Elementor Google Fonts swap setting

If editing CSS manually, append &display=swap to Google font URLs, or add:

@font-face {
  font-family: "Your Font";
  src: url("your-font.woff2") format("woff2");
  font-display: swap;
}

Preload Above-the-Fold Fonts

Preloading critical fonts can prevent FOIT and completely remove layout shifts. Steps:

  1. Host fonts locally to avoid third-party delays.
  2. Identify high-priority font files from your PSI report.
  3. Add preload hints in your <head> with as="font" crossorigin.

Elementor host Google Fonts locally and preload
Local vs third-party fonts

Example preload tag:

<link rel="preload" href="/fonts/your-font.woff2" as="font" crossorigin>

After applying these changes, re-run PageSpeed Insights to confirm the issue is resolved.

Cheers,
Tom

Leave a Comment