Web font optimization and text formatting graphic

We’ve all been there: you open a page, start to read, and suddenly, the text shifts violently when custom web fonts finally snap into place. This isn’t just poor user experience, but a huge hit on your Core Web Vitals that hurts your search visibility because it increases your CLS (Cumulative Layout Shift) metrics.

To fix this, you need to apply font-display: swap that bypasses the browser’s invisible text block period and deploys metric-matched system fallback fonts to kill off the layout jump and preloads critical files to optimize page delivery.

This may sound easy, but in reality, it’s an advanced developer-grade fix that might require professional help to execute a comprehensive Core Web Vitals audit first, and then stabilize your layout permanently.

 

Key Takeaways

  • Zero Invisible Text: The font-display: swap eliminates the FOIT (Flash of Invisible Text), as it forces the browser to render text right away using your fallbacks.
  • The FOUT Tradeoff: Simply adding the swap property trades invisible text for a Flash of Unstyled Text (FOUT). If the fallback’s structural footprint and your web font are mismatched, the CLS score will still take a hit.
  • The Ultimate Fix: To achieve a seamless loading cycle, pair font-display: swap with CSS font metric overrides (size-adjust) and HTML resource preloading.

 

How Web Fonts Hurt Core Web Vitals

Poorly calibrated web fonts can damage search visibility and user experiences as they can trigger two distinct loading problems: Flash of Invisible Text (FOIT) and Flash of Unstyled Text (FOUT). In the first scenario, the browser hides your copy while downloading your custom typeface, and users only see blank space. In the second scenario, the browser may display a generic font that can suddenly transform into your custom option. This reshapes the characters, changes line wraps, and shifts the entire content.

When you’re optimizing fonts for Core Web Vitals, you need to address these rendering delays as they hurt your performance metrics.

 

Cumulative Layout Shift (CLS)

Cumulative Layout Shift measures the webpage’s visual stability while it loads. When you have a faulty font display swap in place, and the custom font replaces the system fallback, the different character dimensions and spacing will force the text blocks to reset.

This structural recalibration changes the entire layout, causing buttons and the text to move and jump while you’re reading, degrading user experience and damaging your CLS score, which in turn weakens your search visibility potential.

 

Largest Contentful Paint (LCP)

This metric tracks when the largest visual element above the fold becomes visible (readable) on your screen. On corporate blogs, text-dense landing pages, and massive eCommerce product listings, the LCP is usually the introductory block or the main header.

When rendering stalls because of heavy web font assets, the primary content remains invisible, hurting LCP timing and degrading perceived page speed.

 

Interaction to Next Paint (INP)

Fonts also have a limited, indirect impact on your INP score. Unoptimized font delivery may crowd the browser’s single main thread. And if it has to parse unoptimized font files at the same time it is trying to run heavy JavaScript files, it causes noticeable input delay.

Streamlining your font-loading assets clears execution overhead on the main thread, allowing the browser to respond to user inputs faster.

 

Font-display: swap and Choosing the Right Font-display Value

 

What font-display: swap Actually Does

The font-display: swap literally tells the browsers to change font-loading behavior. Normally, browsers hide your text for up to 3 seconds, as they wait for your custom web fonts to download. With the help of the font-display: swap property, you tell the browser to skip the waiting period and render the entire text with locally available system fonts (like Arial or Times New Roman), swapping in the custom option seamlessly after download. This makes the content instantly readable.


    @font-face{ 
    font-family: 'Inter';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url('/fonts/inter-latin-subset.woff2') format('woff2');

    /* Target only standard Latin characters to reduce payload size */
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, 
    U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, 
    U+2212, U+2215, U+FEFF, U+FFFD;
 }

 

Swap vs Optional vs Fallback vs Block vs Auto

Depending on your performance goals, swap may not always be your best choice. As a matter of fact, the CSS Fonts Module Level 4 specification dictates how browsers balance layout shifts against invisible text.

font-display valueBlock Period (Invisible Text)Swap Period (System to Custom Font)Best Use Case
swap0 secondsInfiniteCritical body text and main headings where reading the content instantly is vital.
optionalExtremely short (~100ms)0 secondsBody copy on slow networks. If the font isn’t instant, it drops the custom font entirely for that page view to prevent layout shifts.
fallbackExtremely short (~100ms)Short (~3s)UI elements, buttons, or labels where you prefer the custom look but won’t tolerate a late shift.
blockLong (Max 3s)InfiniteIcon fonts (like FontAwesome), where a system text fallback would render as a broken square box.
autoBrowser default (usually 3s)InfiniteDefault behavior. Not recommended for modern performance optimization.

 

Why font-display: swap Alone still Shifts

You may find that the dashboard in PageSpeed Insights will still flag layout shift issues even if you did add the right properties. This happens because swap will inherently lead to FOUT.

This is because every font has its unique properties, like letter-spacing differences, character width, and height. When the browser uses the fallback (let’s say, Arial), the characters might be wider, suddenly changing the layout.

Let’s say the text that took up two lines now needs three, causing a significant shift. To remedy this, you need to match the fallback’s physical proportions to your custom font.

 

Kill the Swap Shift with Metric-Matched Fallbacks

Using the font-display: swap method prevents the text from being invisible, but the Flash of Unstyled Text can still cause layout shifts. As such, you need to match the physical proportions of the fallbacks to the custom web font you’re using.

Modern CSS takes care of this with four metric descriptors inside the @font-face declaration. The properties allow you to alter the local fallback fonts so they take up the same layout footprint as the custom typography.

  • size-adjust: This scales the fallback font’s overall dimensions without changing line height.
  • ascent-override: This modifies the maximum height of uppercase letters and ascending stems (like the top of a “d” or “h”).
  • descent-override: This adjusts the depth of descending stems (like the bottom of a “p” or “g”).
  • line-gap-override: Specifies the explicit spacing or padding added between consecutive lines of text.

This can take a while and may introduce a lot of guesswork to work out the exact percentages. There are specialized dev tools like Fallback Font Generator and Capsize, which analyze your primary web font file and adjust the fallback’s values automatically.


    /* 1. Create a customized system fallback that mimics your custom font's dimensions */
    @font-face{ font-display:swap;
    font-family: 'Adjusted Arial Fallback';
    src: local('Arial');
    size-adjust: 107.4%; 
    ascent-override: 90.3%; 
    descent-override: 21.2%; 
    line-gap-override: 0%;
 }

    /* 2. Layer your font stack cleanly */
    font-family: 'Inter', 'Adjusted Arial Fallback', sans-serif;

When using this workflow, the browser will render the local system fonts instantaneously, with matching dimensions. When your custom fonts finish downloading and swap in, the transition will be flawless, without any line breaks or moving elements.

If you want to build a strong typography foundation, you need to make sure that you pair your custom layouts with optimized, safe, fast-loading system font stacks.

Optimize Web Fonts The Right Way: Make Fonts Load Faster (The Speed Half)

Using the font-display: swap method does protect your user experience, but the goal should be having custom fonts that load so fast that browsers don’t even have to resort to fallbacks. Here is how to speed up your asset delivery process.

 

Preload and Preconnect

Browsers usually do not download web fonts until they have fully fetched your site’s HTML, parsed the CSS, and confirmed that a specific font weight is being used on your page. This can create huge delays.

You can bypass this delay by using resource hints in your HTML <head>:

  • preconnect: If you must resort to third-party font providers like Google Fonts, using preconnect can help you kickstart the DNS lookup, TCP handshake, and TLS negotiation early.
  • preload: For fonts in critical places (like your page’s primary heading), using preload forces the browser to download the file alongside the CSS immediately.


<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="preload" href="/fonts/inter-latin-subset.woff2" as="font" type="font/woff2" crossorigin>

 

Important Note: Always include the crossorigin attribute when preloading fonts, even if the files live on your own domain. Without it, the browser will fetch the asset twice, completely wiping out your performance advantage.

 

Self-Host vs. Google-Hosted Fonts

Quite a few developers rely on Google Fonts out of sheer convenience, and they assume a clever shortcut is happening behind the scenes. More specifically, if a user visits a popular site that uses the exact same font, their browser will save that file in its local memory (cache). Then, when that same user visits your site, the browser should theoretically pull that file from its memory instantly instead of downloading it again.

The problem is, modern web browsers now use a security measure called shared cache partitioning to prevent cross-site tracking and privacy leaks. This means that browsers now completely isolate the files they download for every individual website. As a result, even if a user has downloaded a standard font (like Open Sans) hundreds of times from other websites, the browser will still treat your site as a separate entity and download the font fresh anyway, eliminating the speed advantage of a shared global CDN.

While the Google Fonts API works well and automatically appends display=swap to your stylesheets when requested, self-hosting your fonts is generally the faster option. When you self-host fonts, the browser doesn’t have to waste time connecting to an outside company’s server. Instead, it can pull your fonts from the same place it gets your images and code, downloading everything together in one quick trip.

On that note, your server infrastructure dictates how fast these local files reach your visitors. That said, even hosting plays a crucial role in SEO, as it optimizes your asset delivery setup.

 

WOFF2 + Subsetting With Unicode-range

Unoptimized, standard web font files will usually contain thousands of currency symbols, special glyphs, and characters for foreign languages you won’t be using.

To maximize speed, you should apply two optimizations:

  • Subsetting: This strips out everything and only keeps the exact character ranges your site needs. For an English-only website, this might mean that the font package can drop from 150KB to 15KB.
  • Enforce WOFF2: You can use the built-in Brotli compression of the Web Open Font Format 2, which will make your file size roughly 30% smaller than classic TTF or WOFF files.

You can declare these precise configurations within your stylesheet using the unicode-range property:


    @font-face{ 
    font-family: 'Inter';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url('/fonts/inter-latin-subset.woff2') format('woff2');
    /* Target only standard Latin characters to reduce payload size */
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
 }

 

Variable Fonts

Traditionally, if your design used four distinct variations of the same font (Regular, Medium, Semi-Bold, and Bold), the browser had to open four separate network requests to fetch four individual file payloads.

You can easily solve this problem if you switch to variable fonts, which consolidate an entire family of styles, slants, and weights into one flexible file package. By combining multiple variations into a single network request, you eliminate the connection burden of making separate calls to your server, keeping your main loading thread clean.

 

How to Add font-display: swap in WordPress

WordPress is the foundation of millions of websites across the internet. One would think that because of that, font-loading is smooth sailing. However, managing fonts can be tricky because there are also loads of page builders, themes, and third-party plugins in the mix. If your WordPress site is throwing an “ensure text remains visible during webfont load” warning in PageSpeed Insights, you can fix it using three different approaches.

 

Method 1: The Code Filter (For Theme Developers)

If you know your way around WordPress code and editing child themes, you can write a filter in the theme’s functions.php file. This script will tell WordPress to interrupt stylesheets coming from Google Fonts and automatically attach display=swap to the URL before loading it.


    function popart_add_font_display_swap($html, $handle, $href, $media) {
    // Proverava da li je u pitanju Google Fonts stylesheet
    if ('google-fonts' === $handle || strpos($href, "://googleapis.com") !== false) {
        // Proverava da li display=swap već postoji, ako ne, dodaje ga
        if (strpos($href, 'display=swap') === false) {
            $new_href = add_query_arg('display', 'swap', $href);
            $html = str_replace($href, esc_url($new_href), $html);
        }
    }
    return $html;
}
add_filter('style_loader_tag', 'popart_add_font_display_swap', 10, 4);

 

Method 2: The Core Web Vitals Plugin Route

If you don’t want to touch your theme files, you may also use performance optimization plugins to handle the background work.

  • WP Rocket: Here, you need to go to Settings, WP Rocket, and under Asset Optimization file the CSS Files section. There, just check the corresponding box for font rendering. This will scan the styles on the site, injecting font-display: swap automatically.
  • Autoptimize: Settings > Autoptimize > Extra. Under the Google Fonts section, select Combine and link defer (includes font-display: swap).
  • Perfmatters: Under your Fonts tab, you need to turn on Local Google Fonts. This downloads the files to your server automatically and rewrites the CSS to include the swap.

 

Method 3: Handling Page Builders (Elementor & Divi)

Modern page builders often write their own custom CSS stylesheets and save them in different cache files inside the /wp-content/uploads/ directory. Because of this, global site plugins sometimes miss them.

If you add an optimization plugin or change font configuration, you should also go to your page builder settings ( in Elementor, it’s under Tools/General), and click Regenerate Files & Data. This forces the builder to rewrite its styling files and correctly apply your new font-swapping rules.

Note that tinkering with caching plugins can sometimes break your layouts if your assets aren’t organized properly. An expert WordPress Development team can safely audit your site, clean up rogue font files, and maximize your loading speed.

 

Measure the Impact (Before & After)

Once the font-display: swap has been implemented, and you’ve also paired your customs with a metric-matched fallback, you need to check whether the changes work or not. Checking performance across different devices and connections ensures that your copy loads perfectly in real-world scenarios.

 

1. Lab Data: Testing with PageSpeed Insights and Chrome DevTools

This is performance testing under controlled conditions, simulating specific device behaviour on a fixed network speed. It helps you debug layout shifts easily.

  • PageSpeed Insights: Enter the URL in the tools bar, and check out the dashboard. The “Ensure text remains visible during webfont load” text should move to the Passed Audits section. Your Cumulative Layout Shift (CLS) score should now drop toward zero.
  • Chrome DevTools Performance Panel: Open your site, press F12, and go to the Performance tab. Check the box for Web Vitals and record a page load. Examine the Experience row. If everything works properly, there will be no more layout shift flags when the swap happens.

 

2. Field Data: Monitoring Google Search Console and CrUX

Lab findings are great for basic debugging, but they do not guarantee that your site will pass Google’s ranking thresholds. This is where field data comes in.

You can pull this data from the Chrome User Experience Report (CrUX). It aggregates the actual loading speeds experienced by real human visitors accessing your site over various mobile networks, locations, and hardware devices worldwide.

  • Google Search Console: Go to the Core Web Vitals and look at your mobile and desktop graphs.
  • The Field Data Timeline: Keep in mind that field data is on a 28-day rolling average. When you fix the layout shift problems, Google Search Console will not give you the green light immediately. You must click Validate Fix inside the console dashboard and monitor the real-world user trends over the following four weeks to see your official scores improve.

Don’t forget, an impeccable score in a lab test means that your code is written correctly. However, if you get visitors on slow 4G networks and your font files are still too heavy, the browsers may still take too long to swap the customs for the fallbacks. To make sure that your field data scores are high as well, you need to ensure that fallback fonts swap almost instantly, no matter the device and connection strength.

 

How to Use font-display: swap Frequently Asked Questions

What does font-display: swap mean?

font-display: swap is a CSS instruction that commands browsers to show your web copy immediately, using local system fonts, while your custom fonts are loading in the background. Once the download’s complete, the browser instantly swaps in the customs. This prevents your text from being invisible to users on slower internet connections.

font-display: swap vs optional vs fallback — which should I use?

We recommend using swap for primary body text and headlines where reading the content immediately is the highest priority. Optional is great for less critical background text, as it will skip the custom font entirely. Given that it cannot load instantly, it will prevent layout shifts. Lastly, use a fallback for interactive UI elements like buttons or menus, where you want to give the custom font a very brief moment to load before falling back.

Why is font-display: swap not working?

If PageSpeed Insights is flagging your fonts after adding the instructions, your font files might likely be handled (loaded) by a third-party plugin, or you are preloading them without the crossorigin attribute. Additionally, advanced page builders like Elementor or Divi require you to manually regenerate their internal file caches before your new font styles will apply live.

How do I add font-display: swap in WordPress?

You can do this by writing a custom PHP filter inside the functions.php file to intercept your enqueued Google Font stylesheets. You may also use performance plugins to optimize your font rendering automatically.

Do web fonts cause layout shift (CLS)?

Yes. Web fonts can cause CLS (Cumulative Layout Shift) if the physical properties, line heights, and letter spacing of the custom font do not match the fallback font’s dimensions perfectly. In these cases, when the custom font swaps into place, the text blocks can re-wrap and resize, causing noticeable content jumps.

How do optimized fonts improve SEO and Core Web Vitals?

When your fonts are optimized, you directly improve your site’s Largest Contentful Paint (LCP) score, as it will make the above-fold text immediately visible. Optimized fonts will also fix CLS when they are paired with metric-matching CSS overrides. Because these metrics directly influence Google’s ranking algorithms, fixing your font delivery helps protect your technical SEO and search visibility.

How do I fix font layout shift in Next.js?

You can use the built-in next/font module. This optimizes, subsets, and self-hosts your typography automatically at the build level. The module will also calculate the exact CSS font metric overrides for your fallbacks, without manual configuration.

 

Final Thoughts

If you want to fix CLS permanently, you need a solid optimization strategy and set up your process deliberately. Changing a single CSS property often won’t be enough to resolve a complex asset delivery bottleneck. Instead, engineering an optimal typography stack follows a clear blueprint:

[Diagnose Shifts via DevTools] ➔ [Apply font-display: swap] ➔ [Inject Metric-Matched Fallbacks] ➔ [Preload Above-the-Fold Fonts] ➔ [Self-Host compressed WOFF2 Subsets] ➔ [Verify Field Data Trends]

When you address every stage of the font-loading processes, you can eliminate FOUT jumps and invisible text delays. While optimizing your fonts probably won’t grant you a top spot in the search results alone, it will stabilize your layout and speed up text rendering, protecting your technical Core Web Vitals and creating a better user experience.

Balancing page performance and custom design requires adept technical knowledge. Contact a seasoned web development team that can audit your asset delivery processes and fix layout shifts permanently, optimizing user experience in the process.

Szabolcs Szecsei

Szabolcs Szecsei born on February 4th, 1989, A Hungarian writer, living in Novi Sad, Serbia. With a master’s degree in Communication and Media Studies, Szabolcs has been working in the news and marketing industry for more than six years. Apart from writing, Szabolcs is also a professional touring and recording musician, working for several bands and projects.