Check 06.16 · Performance and Core Web Vitals

Optimize fonts (WOFF2, font-display)

Serve your fonts as WOFF2 from your own domain, set font-display and preload the critical font: code for servers, CMSs and common frameworks.

Priority
Important
Difficulty
Intermediate
Estimated time
1 to 3 h
Free, no account: your progress is saved in this browser.

Ask an AI to check this point on your site

Opens the assistant with a ready-made question: this check, its goal and your site URL.

For Gemini, Copilot or another assistant, copy the question. The link opens the chosen service directly: nothing goes through this site.

In short

A poorly loaded web font delays the display of text, then makes it jump when it arrives. This check consists of reducing the number of files, serving them in WOFF2 format from your own domain, declaring font-display so that text appears immediately in a fallback font, and preloading the one or two fonts that are truly critical. Expected result: readable text from the very first render, with no visible shift when the fonts are swapped.

Why it matters

The browser only discovers a font after downloading the HTML, then the CSS, then noticing that some visible text uses it. The request therefore starts late. In the meantime, the default behavior of most browsers is to keep the text invisible for a period of up to three seconds: this is FOIT (Flash Of Invisible Text). If the largest visible element on the page is a heading or a paragraph, the LCP (Largest Contentful Paint) waits for the font.

The font-display descriptor controls this behavior:

Value Invisible text Late swap Use
auto depends on the browser, often like block yes avoid
block up to about 3 s yes icon fonts
swap almost none yes, with no limit body text and headings
fallback very short (about 100 ms) yes, during a short window compromise
optional very short (about 100 ms) no stability comes first

With swap, the text appears immediately in the fallback font, then changes when the web font arrives. If the two fonts do not have the same proportions, lines reflow and the page moves: this is a layout shift, counted in CLS (Cumulative Layout Shift). Hence the value of adjusting the fallback font's metrics.

Finally, a font loaded from a third-party service requires a connection to another domain and passes the visitor's IP address to that third party. Self-hosting removes both drawbacks.

What it improves

  • LCP when the main element is text, and first display in every case.
  • CLS Less reflow at the moment the font is swapped.
  • Page weight WOFF2 is the most compact format, and a character subset cuts the file size further.
  • Privacy No request to a third-party font service.
  • Rankings Indirect effect, through Core Web Vitals.

How to check

In the developer tools, Network tab, “Font” filter, reload the page:

  • all files are .woff2;
  • they come from your domain;
  • there are few of them, and each matches a weight that is actually visible on the page;
  • the main text font has high priority and starts early in the waterfall.

List the declared fonts and their setting in the console:

[...document.fonts].map((font) => ({
  family: font.family,
  weight: font.weight,
  display: font.display,
  status: font.status,
}));

No line should show display: "auto" or "block" for a text font. Fonts with the unloaded status are declared but unused on the page: normal for rare weights, suspicious if they are preloaded.

Check the headers of a font file:

curl -s -o /dev/null -D - https://example.com/fonts/inter-latin.woff2 | grep -i -E "content-type|cache-control"

Compliant result:

content-type: font/woff2
cache-control: public, max-age=31536000, immutable

PageSpeed Insights also flags fonts without a suitable font-display. See analyze PageSpeed Insights and Lighthouse (opens in a new tab).

How to implement

Before you start

Reduce the need. One family for headings and one for body text, at most. A variable font replaces all the weights with a single file. For a plain interface, the system stack (font-family: system-ui, sans-serif) costs no request at all.

Produce WOFF2 files limited to the characters you need. With fonttools, for Western European languages:

pip install fonttools brotli
pyftsubset Inter.ttf \
  --output-file=inter-latin.woff2 \
  --flavor=woff2 \
  --layout-features='*' \
  --unicodes="U+0000-00FF,U+0131,U+0152-0153,U+02C6,U+02DA,U+02DC,U+2000-206F,U+20AC,U+2122,U+2212"

Check that the font's license allows conversion and self-hosting. For a Google Fonts font, the Fontsource project and the google-webfonts-helper tool provide WOFF2 files that are already subset.

Declare the font and its adjusted fallback:

@font-face {
  font-family: "Inter";
  src: url("/fonts/inter-latin.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Inter Fallback";
  src: local("Arial");
  size-adjust: 107%;
  ascent-override: 90%;
  descent-override: 22%;
  line-gap-override: 0%;
}

body {
  font-family: "Inter", "Inter Fallback", sans-serif;
}

The percentages above are an example for the Inter and Arial pair. Calculate those for your own font with a tool such as Fontaine or Capsize.

Preload only the font of the text visible at load time:

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

Warning: the crossorigin attribute is mandatory, even for a font served from your own domain. Without it, the browser downloads the file twice.

If you keep Google Fonts, add &display=swap to the stylesheet URL and preconnect to the domain that serves the files:

<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap">

Apache

Versions Apache 2.4.

In the virtual host configuration or the .htaccess file:

AddType font/woff2 .woff2

<IfModule mod_headers.c>
    <FilesMatch "\.woff2$">
        Header set Cache-Control "public, max-age=31536000, immutable"
    </FilesMatch>
</IfModule>

If the fonts are served from a different domain from the pages (static subdomain, CDN), add to the same FilesMatch block: Header set Access-Control-Allow-Origin "https://www.example.com". Reload with sudo apachectl configtest && sudo systemctl reload apache2.

Nginx

Versions Nginx 1.18 and later.

Check that /etc/nginx/mime.types contains the line font/woff2 woff2;, then add to the server block:

location ~* \.woff2$ {
    add_header Cache-Control "public, max-age=31536000, immutable";
}

For a separate font domain, add add_header Access-Control-Allow-Origin "https://www.example.com"; to this block. Test and reload: sudo nginx -t && sudo systemctl reload nginx.

A one-year cache assumes versioned file names. See configure browser and server caching (opens in a new tab).

Cloudflare

Versions Cloudflare dashboard, all plans, November 2026.

Cloudflare Fonts (Speed > Settings > Content Optimization) rewrites the HTML on the fly: links to Google Fonts are replaced with inline CSS, and the font files are served from your own domain. Documented limitations: only Google fonts loaded with a <link> tag are supported (not the @import method), and a restrictive CSP can block the mechanism. It is a quick solution when you cannot modify the theme.

WordPress

Versions WordPress 6.6 and later (up to 7.1) for theme.json version 3; Font Library since 6.5.

Block themes. Since WordPress 6.5, the Font Library (Appearance > Editor > Styles > Typography) installs Google fonts on your server instead of loading them from Google. In a theme, declare the local files in theme.json:

{
  "version": 3,
  "settings": {
    "typography": {
      "fontFamilies": [
        {
          "fontFamily": "Inter, sans-serif",
          "slug": "inter",
          "name": "Inter",
          "fontFace": [
            {
              "fontFamily": "Inter",
              "fontWeight": "100 900",
              "fontStyle": "normal",
              "fontDisplay": "swap",
              "src": ["file:./assets/fonts/inter-latin.woff2"]
            }
          ]
        }
      ]
    }
  }
}

Classic themes. Find the wp_enqueue_style call in functions.php that points to fonts.googleapis.com and replace it with a local stylesheet containing your @font-face rules. If you cannot modify the theme, the OMGF plugin downloads Google fonts and serves them locally; common caching plugins (WP Rocket, LiteSpeed Cache, Perfmatters) also have options dedicated to Google fonts.

Preloading, in functions.php:

add_filter('wp_preload_resources', function (array $resources): array {
    $resources[] = [
        'href' => get_theme_file_uri('assets/fonts/inter-latin.woff2'),
        'as' => 'font',
        'type' => 'font/woff2',
        'crossorigin' => 'anonymous',
    ];

    return $resources;
});

Page builders (Elementor, Divi) have their own setting for loading Google fonts: look for the font-display option and the local hosting option in their performance settings.

Shopify

Versions Online Store 2.0 themes, all Shopify plans, November 2026.

The font_face filter generates the @font-face declaration for a font chosen in the theme settings. Add font_display to it:

{% style %}
  {{ settings.type_body_font | font_face: font_display: 'swap' }}
  {{ settings.type_header_font | font_face: font_display: 'swap' }}
{% endstyle %}

<link rel="preload" as="font" href="{{ settings.type_body_font | font_url }}" type="font/woff2" crossorigin>

Fonts from the Shopify font library are served by the store's CDN: there is no third-party domain to contact. For a custom font, upload the WOFF2 file to assets and write the @font-face rule with {{ 'ma-police.woff2' | asset_url }}.

PrestaShop

Versions PrestaShop 8 and 9.

Fonts are declared in the theme's stylesheets (themes/votre-theme/assets/css/ or the sources in the _dev folder). Check that each @font-face references a local WOFF2 file and contains font-display: swap. Modules that add a Google font through a displayHeader hook should be disabled in favor of a local font. Clear the cache in Advanced Parameters > Performance.

Magento

Versions Magento Open Source and Adobe Commerce 2.4.4 to 2.4.9, themes based on Blank or Luma.

In a theme based on Blank or Luma, fonts are declared with the .lib-font-face mixin in web/css/source/_typography.less. Its @font-display parameter defaults to auto: change it to swap.

.lib-font-face(
    @family-name: 'Inter',
    @font-path: '@{baseDir}fonts/inter/inter-latin',
    @font-weight: 400,
    @font-style: normal,
    @font-display: swap
);

Place the files in web/fonts/inter/, then redeploy the static content (bin/magento setup:static-content:deploy). The mixin itself appends the .woff2 and .woff extensions to the path given.

Drupal

Versions Drupal 10 and 11.

Declare your @font-face rules in a theme stylesheet registered in montheme.libraries.yml. For preloading, in montheme.theme:

function montheme_page_attachments_alter(array &$attachments): void
{
    $attachments['#attached']['html_head_link'][] = [
        [
            'rel' => 'preload',
            'href' => '/themes/custom/montheme/fonts/inter-latin.woff2',
            'as' => 'font',
            'type' => 'font/woff2',
            'crossorigin' => 'anonymous',
        ],
    ];
}

Wix

Versions Wix Editor and Wix Studio, all plans, November 2026.

Font loading is handled by the platform: there is no setting for font-display or preloading. Your only lever is to limit the number of families and weights used in the theme. The same applies to Squarespace.

Webflow

Versions Webflow Designer, all plans, November 2026.

In Site settings > Fonts, upload your WOFF2 files as custom fonts and choose Swap in each font's display setting. Google fonts added from the interface are loaded by a script: prefer uploading the files.

Laravel

Versions Laravel 10 to 13; font handling by Vite with Laravel 13 and laravel-vite-plugin 3.1 and later (Vite 8).

Laravel 13 with laravel-vite-plugin 3.1 or later

Laravel's Vite plugin handles fonts: self-hosted files, CSS generated with font-display: swap by default, preloading and an adjusted fallback (with the fontaine package, installed with npm install --save-dev fontaine). In vite.config.js:

import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import { local } from 'laravel-vite-plugin/fonts';

export default defineConfig({
    plugins: [
        laravel({
            input: ['resources/css/app.css', 'resources/js/app.js'],
            fonts: [
                local('Inter', {
                    alias: 'sans',
                    src: 'resources/fonts/inter/*.woff2',
                    display: 'swap',
                    preload: [{ weight: 400 }],
                    fallbacks: ['system-ui', 'sans-serif'],
                }),
            ],
        }),
    ],
});

In the template's <head>, the @fonts directive writes the preloads and the font CSS:

<head>
    @fonts
    @vite(['resources/css/app.css', 'resources/js/app.js'])
</head>

The google('Inter', { ... }) provider downloads a Google font at build time instead of reading local files; bunny() and fontsource() are also available.

Laravel 10 to 12, or plugin earlier than 3.1

Place the file in public/fonts, write the @font-face rule in your CSS and preload it in the <head>:

<link rel="preload" href="{{ asset('fonts/inter-latin.woff2') }}" as="font" type="font/woff2" crossorigin>

Symfony

Versions Symfony 6.4 to 8.1, with AssetMapper.

With AssetMapper, place the fonts in assets/fonts and reference them with a relative path in your CSS: the files are versioned automatically. Preloading in the base template:

<link rel="preload" href="{{ asset('fonts/inter-latin.woff2') }}" as="font" type="font/woff2" crossorigin>

Next.js

Versions Next.js 15 and 16 (App Router).

next/font downloads the font at build time, hosts it with your static files, generates an adjusted fallback font and preloads the requested subset. The browser sends no request to Google.

import { Inter } from 'next/font/google';

const inter = Inter({
  subsets: ['latin'],
  display: 'swap',
});

export default function RootLayout({ children }) {
  return (
    <html lang="fr" className={inter.className}>
      <body>{children}</body>
    </html>
  );
}

For your own file, use next/font/local with src: './inter-latin.woff2'.

Nuxt

Versions Nuxt 3 and 4, Nuxt Fonts module 0.x and 1.x.

The Nuxt Fonts module detects the families used in your CSS, downloads the files, serves them from your domain and generates the fallback metrics:

npx nuxt module add fonts

All you then need to do is write font-family: "Inter", sans-serif; in your styles.

Astro

Versions Astro 6 and 7.

Astro's fonts API self-hosts the files and generates an optimized fallback. In astro.config.mjs:

import { defineConfig, fontProviders } from 'astro/config';

export default defineConfig({
  fonts: [
    {
      provider: fontProviders.fontsource(),
      name: 'Inter',
      cssVariable: '--font-inter',
    },
  ],
});

In the layout's <head>:

---
import { Font } from 'astro:assets';
---
<Font cssVariable="--font-inter" preload />

Then use font-family: var(--font-inter);. From version 5.7 to the last 5.x release, this API was only available as an experimental feature (the experimental.fonts option) and its syntax changed from one minor version to the next: upgrade to Astro 6, or install the font's Fontsource package and import it in the layout.

Common mistakes

  • Preloading every weight: each preload competes with the CSS and the main image. One or two fonts, no more. See preload only critical resources (opens in a new tab).
  • Forgetting crossorigin on the preload: double download.
  • Preloading a different file from the one in the @font-face rule (another subset, another versioned name): the font is downloaded for nothing.
  • Keeping TTF, EOT or WOFF formats “for compatibility”: all current browsers read WOFF2.
  • font-display: swap on an icon font: unrelated characters are displayed before the font arrives. Use block, or better, SVG icons.
  • swap without an adjusted fallback on a font with very different proportions: the text appears quickly but the page jumps.
  • Compressing WOFF2 files with Gzip or Brotli: the format is already compressed. See enable Brotli or Gzip (opens in a new tab).
  • Loading the same family twice: once through the theme, once through a plugin or a page builder.

Frequently asked questions

Which font-display value should I choose?

For body text and headings, choose swap: the text appears immediately in the fallback font, then changes when the web font arrives. If stability comes first, optional avoids any late swap, at the cost of not showing the web font on a slow first visit. Keep block for icon fonts, and avoid auto, which browsers often treat as block.

Should I host Google Fonts on my own server?

It is preferable. A font loaded from Google requires a connection to another domain before the text is displayed, and passes the visitor's IP address to that third party. Self-hosted as WOFF2 on your domain, it removes both drawbacks. Check that the license allows it; Fontsource, next/font, Nuxt Fonts or the WordPress Font Library make the job easier.

Do I still need to provide TTF, EOT or WOFF formats?

No. All current browsers read WOFF2, the most compact font format. Keeping TTF, EOT or WOFF “for compatibility” makes the declarations heavier for no benefit. Serve a single WOFF2 file per weight, or a variable font that groups them all, limited to the characters you need. Do not compress it with Gzip or Brotli: the format is already compressed.

Why is the crossorigin attribute required to preload a font?

Fonts are always requested in CORS mode, even from your own domain. A preload without the crossorigin attribute therefore does not match the request the browser will make for the @font-face rule, and the file is downloaded twice. Also specify as="font" and type="font/woff2", and only preload the one or two fonts of the text visible at load time.

Resources

Updated on

Topic checklist (PDF)

And now?

In the “Performance and Core Web Vitals” topic

  1. Analyze PageSpeed Insights and Lighthouse
  2. Analyze real-user CrUX data
  3. Target LCP ≤ 2.5 s at the 75th percentile
  4. Target INP ≤ 200 ms at the 75th percentile
  5. Target CLS ≤ 0.1 at the 75th percentile
  6. Target TTFB ≤ 800 ms as a benchmark
  7. Optimize hosting and CDN
  8. Enable Brotli/Gzip
  9. Configure browser and server caching
  10. Minify CSS and JavaScript
  11. Remove unused CSS/JS
  12. Reduce render-blocking resources
  13. Defer non-essential scripts
  14. Limit third-party scripts
  15. Optimize database queries
  16. Optimize fonts (WOFF2, font-display)
  17. Preload only critical resources
  18. Optimize the LCP image without lazy loading
  19. Lazy-load offscreen content
  20. Reserve space for media and ads
  21. Reduce DOM complexity
  22. Test before and after cookie consent
  23. Test on a slow mobile connection
  24. Set a performance budget
  25. Preload likely navigations with Speculation Rules
  26. Make pages eligible for the back/forward cache (bfcache)
  27. Diagnose INP with Long Animation Frames (LoAF)