Menu

font-display: swap Fixes Invisible Text. It Also Shifts Your Layout.
📰

font-display: swap Fixes Invisible Text. It Also Shifts Your Layout.

DEV Community·Parsa J·about 5 hours ago
#TOjWXu6J
#devcommunity#dev#font#swap#fallback
Reading 0:00
15s threshold

The ticket said "homepage CLS regressed after the rebrand." Nobody had touched the layout. Nobody had touched the images. The only diff in that deploy was a font swap — the body copy went from a system font to a licensed one, loaded from @font-face .

Lighthouse didn't care that the new font looked better. It saw text that painted in one spot, then jumped, and it scored that jump like it scores a banner ad shoving the article down the page.

The fix everyone reaches for here is font-display: swap . It was already set. That was the problem.

The belief: "swap" is the whole fix

Here's the belief, and it's not wrong, exactly: web fonts load over the network, and by default most browsers render nothing until the font arrives — the flash of invisible text, FOIT. You add font-display: swap to your @font-face rule, the browser paints your fallback font immediately, and swaps in the real font the moment it's ready. No more invisible text. Problem solved.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.