日本語

How to Fix Lighthouse’s font-display Warning

​​Lighthouse​Core Web Vitals,CSS,Fonts,Google Fonts

The Lighthouse "Font display" warning goes away when you set font-display: swap or font-display: optional in @font-face. (When the report is in Japanese, this item shows a translated label.) Check this when a page using web fonts or Google Fonts loads slowly, or when you want to reduce LCP (the time until the largest text or image is displayed), one of the Core Web Vitals. On the page I tested, changing font-display: block to swap dropped Lighthouse's LCP from 3.9 s to 0.6 s, and the performance score rose from 88 to 100. I ran Lighthouse in the test environment and include its output as is.

Note

The test environment was Ubuntu 24.04, Node.js 22, and Lighthouse 13.6.0 (the npm package). I ran Lighthouse from the command line with its default settings (mobile), only the performance category, and three runs per page. For comparison, I also ran each page once with Lighthouse 12.8.2. The test pages were served from a small server running in the test environment (localhost:8080). Only the web font (an Inter .otf file of about 590 KiB) was delayed by 1.5 seconds. Chrome was Chrome for Testing 153, bundled with Playwright 1.63.0. I did not test the Lighthouse panel in Chrome DevTools, PageSpeed Insights, desktop settings, results on live sites, or fonts loaded with the JavaScript FontFace API.

In Lighthouse 13, it appears as "Font display"

In Lighthouse 13.6.0, this warning is reported as the font-display-insight item, under "Insights" in the report, with the name "Font display". If you run with --locale=ja, the label is translated into Japanese.

In Lighthouse 12.8.2, which I used for comparison, the older font-display item appeared alongside this new one, named "Ensure text remains visible during webfont load" (its Japanese label is a translation of this name). The source code of Lighthouse 13.6.0's font-display-insight says it replaces this older item (replacesAudits: ['font-display']). The JSON report from 13.6.0 that I tested also had no older font-display item. If you search for the older item name and find nothing, look for "Font display" instead.

The page that triggered the warning and Lighthouse's output

The warning appeared on a page that loads a web font with @font-face and sets font-display: block. Both the headings and the paragraphs use this font.

html
<style>
@font-face {
  font-family: "NekoSans";
  src: url("/inter.otf") format("opentype");
  font-display: block;
}
body { font-family: "NekoSans", sans-serif; margin: 0 auto; max-width: 640px; padding: 0 16px; }
</style>

I ran Lighthouse on this page. Chrome was set through the CHROME_PATH environment variable to Chrome for Testing 153 (the path is replaced with a placeholder). I used a small script I wrote (summarize.mjs) to pull the score, the metrics, and this item's result out of the JSON output.

console
$ export CHROME_PATH=/path/to/chrome-153
$ npx lighthouse http://localhost:8080/block.html --only-categories=performance --output=json --output=html --output-path=./out/block-1 --chrome-flags="--headless=new --no-sandbox" --quiet
$ node summarize.mjs out/block-1.report.json
lighthouseVersion: 13.6.0  requestedUrl: http://localhost:8080/block.html
performance score: 88  FCP: 0.6 s (score 1)  LCP: 3.9 s (score 0.52)  CLS: 0 (score 1)
font-display-insight: score=0 title="Font display" displayValue="Est savings of 1,500 ms" metricSavings={"FCP":1500,"INP":0}
  - http://localhost:8080/inter.otf  wastedMs=1500

In the HTML report, the item was marked with a red triangle. The table lists the font file and the time that fixing it was estimated to save (Est Savings).

Lighthouse report with the Font display item expanded. A red triangle and the text "Est savings of 1,500 ms" are shown, and the table lists /inter.otf and 1,500 ms
Report for the font-display: block page. The font file is listed

The estimate of 1,500 ms is the time it took to download the font. The source code of Chrome DevTools' FontDisplay measures the time from sending the font request until the response finishes, and caps it at 3,000 ms on the basis that "browsers wait at most 3 seconds." On this page, the font was delayed by 1.5 seconds, so that time appeared as is.

As the item's "Unscored" label shows, this item does not count toward the score. In the Lighthouse 13.6.0 settings, its weight is 0. The score dropped to 88 mainly because LCP was slow at 3.9 s, which gave the LCP score (weight 25) a value of 0.52. (The Speed Index score was 0.98.)

Change font-display to swap

I changed the font-display value in @font-face to swap. This is the only line I changed.

diff
 @font-face {
   font-family: "NekoSans";
   src: url("/inter.otf") format("opentype");
-  font-display: block;
+  font-display: swap;
 }

According to the MDN reference for font-display, block gives a short block period, during which text stays invisible while the font is loading, and swap makes this period extremely small. With swap, text is shown in a fallback font until the web font arrives, and then the browser swaps it in.

After I ran Lighthouse again, the warning was gone. LCP was 0.6 s, and the scores were 99, 100, and 100.

console
$ npx lighthouse http://localhost:8080/swap.html --only-categories=performance --output=json --output=html --output-path=./out/swap-2 --chrome-flags="--headless=new --no-sandbox" --quiet
$ node summarize.mjs out/swap-2.report.json
lighthouseVersion: 13.6.0  requestedUrl: http://localhost:8080/swap.html
performance score: 100  FCP: 0.6 s (score 1)  LCP: 0.6 s (score 1)  CLS: 0 (score 1)
font-display-insight: score=1 title="Font display" displayValue="" metricSavings={"INP":0}

In the report, the item had a green circle and moved to "Passed audits".

Lighthouse report with the Font display item marked with a green circle and its table removed
Report after changing to font-display: swap. No font files are listed

I also compared the LCP that the browser actually recorded. The audits.metrics section of the Lighthouse JSON holds both the observed values and the values Lighthouse calculated. I used another script I wrote (obs-lh.cjs) to extract them. The block page had an observed LCP of 1,569 ms, and the swap page had 91 ms. The observed LCP of the block page was almost the same as the 1.5 s font delay.

The 3.9 s in the Lighthouse report is a value recalculated from these observations. The settings for this run used throttlingMethod: simulate (150 ms round-trip time, about 1.6 Mbps, and a CPU 4 times slower). The Lighthouse throttling guide says this simulation is the default, and that it calculates page load from the data observed during the first load.

console
$ node obs-lh.cjs out/{none,block,fallback,swap,optional}-1.report.json
none-1: observed FCP=75ms LCP=1608ms / Lighthouse FCP=624ms LCP=3902ms
block-1: observed FCP=38ms LCP=1569ms / Lighthouse FCP=617ms LCP=3902ms
fallback-1: observed FCP=59ms LCP=165ms / Lighthouse FCP=604ms LCP=604ms
swap-1: observed FCP=91ms LCP=91ms / Lighthouse FCP=607ms LCP=607ms
optional-1: observed FCP=71ms LCP=71ms / Lighthouse FCP=607ms LCP=607ms

The report labels this item with "FCP", and the estimated savings were also shown as an FCP reduction. But on this page, FCP was already 0.6 s before the change, and it was LCP that dropped.

Results by value: fallback is also flagged in Lighthouse 13

I tested the same page without font-display, and with four of the five values: block, fallback, swap, and optional. For Lighthouse 13.6.0, the scores and LCP are from three runs. For Lighthouse 12.8.2's older item, the result is from one run.

font-display Font display in 13.6.0 Scores over 3 runs LCP Older item in 12.8.2
not set Flagged (1,500 ms) 88, 88, 89 3.8–3.9 s Flagged
block Flagged (1,500 ms) 88, 88, 88 3.9 s Passed
fallback Flagged (1,500–1,510 ms) 100, 99, 100 0.6 s Passed
swap Passed 99, 100, 100 0.6 s Passed
optional Passed 100, 100, 100 0.6 s Passed

The source code of Chrome DevTools' FontDisplay sets the values it flags with /^(block|fallback|auto)$/. (The same code used by Lighthouse 13.6.0 is included in the npm package @paulirish/trace_engine 0.0.67.) When font-display is not set, the value is auto, so it is flagged too. Chrome for Developers' guide to Font display also says to use swap or optional to pass.

On the other hand, the source code of Lighthouse 12.8.2's older item passes the values /^(block|fallback|optional|swap)$/. So in the older 12.8.2 item, only pages without font-display were flagged, and block passed. A page you fixed by setting block based on Lighthouse 12 results will still be flagged in Lighthouse 13.

Point

To clear the warning in Lighthouse 13, set font-display to swap or optional. With fallback, the warning remained even though the score was 100.

Choose between swap and optional based on how you want the page to behave when the font arrives late. According to the MDN reference, swap replaces the fallback font whenever the web font arrives, however late it is, while optional allows no swap after the short block period. On this page, CLS was 0 for both.

For Google Fonts, add display=swap to the URL

When you load Google Fonts with a <link> tag, the @font-face rules come from the CSS that Google Fonts returns, and you do not write them yourself. In this case, add display=swap to the CSS URL. In the test environment, I used curl to fetch the CSS that Google Fonts returns and compared the results (only the latin part is shown).

console
$ curl -s -A "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 Chrome/153.0.0.0 Safari/537.36" "https://fonts.googleapis.com/css2?family=Roboto" | sed -n "/\/\* latin \*\//,/}/p"
/* latin */
@font-face {
  font-family: 'Roboto';
  font-style: normal;
  font-weight: 400;
  font-stretch: 100%;
  src: url(https://fonts.gstatic.com/s/roboto/v51/KFOMCnqEu92Fr1ME7kSn66aGLdTylUAMQXC89YmC2DPNWubEbVmUiAo.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

With a URL that has no display parameter, the returned @font-face had no font-display line. With &display=swap added, a font-display: swap; line appeared after font-stretch. With &display=optional, the line was font-display: optional;.

html
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Roboto&display=swap">

I ran Lighthouse once on a page with each of these two forms. The fonts were loaded from Google Fonts on the internet. The page without a display parameter was flagged with an orange square. The estimate was "Est savings of 10 ms".

Lighthouse report with the Font display item marked by an orange square and the text "Est savings of 10 ms", and a table listing Google Fonts woff2 files
Report for the page that loads Google Fonts without display
console
$ node summarize.mjs out/gf-none-1.report.json
lighthouseVersion: 13.6.0  requestedUrl: http://localhost:8080/gf-none.html
performance score: 98  FCP: 1.4 s (score 0.97)  LCP: 2.3 s (score 0.93)  CLS: 0 (score 1)
font-display-insight: score=0.5 title="Font display" displayValue="Est savings of 10 ms" metricSavings={"FCP":0,"INP":0}
  - https://fonts.gstatic.com/s/roboto/v51/KFOMCnqEu92Fr1ME7kSn66aGLdTylUAMQXC89YmC2DPNWubEbVmUiAr0lFQm.woff2  wastedMs=5
$ node summarize.mjs out/gf-swap-1.report.json
lighthouseVersion: 13.6.0  requestedUrl: http://localhost:8080/gf-swap.html
performance score: 100  FCP: 1.4 s (score 0.97)  LCP: 1.4 s (score 1)  CLS: 0 (score 1)
font-display-insight: score=1 title="Font display" displayValue="" metricSavings={"INP":0}

The woff2 file that Lighthouse listed is not the same as the latin file shown in the curl output above. The wastedMs in the JSON was 5, and the report displayed "10 ms". Lighthouse 13.6.0 rounds the estimated savings (FCP) of 5 ms to the nearest 50 ms, so the estimate became 0. In Lighthouse 13.6.0's audit.js, an audit that is flagged but has an estimated saving of 0 gets a score of 0.5. The orange square is the display for this 0.5 score. In this way, the warning appears even in a run where the font arrived quickly. With display=swap, the warning disappeared, and in this single run LCP went from 2.3 s to 1.4 s.

​Posted by 86