Avoid invisible text during font loading


目录

Fonts are often large files that take awhile to load. To deal with this, some browsers hide text until the font loads (the "flash of invisible text"). If you're optimizing for performance, you'll want to avoid the "flash of invisible text" and show content to users immediately using a system font (the "flash of unstyled text").

Display text immediately

This guide outlines two ways to achieve this: the first approach is very simple but does not have universal browser support; the second approach is more work but has full browser support. The best choice for you is the one that you'll actually implement and maintain.

Option #1: Use font-display

Before After
@font-face { font-family: Helvetica; } @font-face { font-family: Helvetica; font-display: swap; }

font-display is an API for specifying font display strategy. swap tells the browser that text using this font should be displayed immediately using a system font. Once the custom font is ready, the system font is swapped out.

{% BrowserCompat 'css.at-rules.font-face.font-display' %}

If a browser does not support font-display, the browser continues to follow its default behavior for loading fonts.

These are the default font-loading behaviors for common browsers:

Browser Default behavior if font is not ready…
Edge Uses a system font until font is ready. Swaps out font.
Chrome Will hide text for up to 3 seconds. If text is still not ready, uses a system font until font is ready. Swaps out font.
Firefox Will hide text for up to 3 seconds. If text is still not ready, uses a system font until font is ready. Swaps out font.
Safari Hides text until font is ready.

Option #2: Wait to use custom fonts until they are loaded

With a bit more work, the same behavior can be implemented to work across all browsers.

There are three parts to this approach:

Here are the changes you can expect to make to implement this:

{% Aside 'codelab' %} Use Font Face Observer to display text immediately. {% endAside %}

Verify

Run Lighthouse to verify the site is using font-display: swap to display text:

{% Instruction 'audit-performance', 'ol' %}

Confirm that the Ensure text remains visible during webfont load audit is passing.


版本号 #2
由 壳壳虫 创建于 2026-10-31 22:33:06 UTC
由 壳壳虫 更新于 2026-10-31 22:33:07 UTC