日本語

How to Fix the Lighthouse “Document doesn’t use legible font sizes” Warning

​​Lighthouse​CSS,HTML,Troubleshooting

When Lighthouse reports "Document doesn't use legible font sizes" (the Japanese report uses a localized title for this audit), more than 40% of the text on the page is smaller than 12px. Make at least 60% of the page text 12px or larger with CSS, and the warning goes away. This warning appears on pages where the body text is small and hard to read on a phone.

In my test environment, I built a page where I had set html { font-size: 62.5%; } but forgot to set a size for the body text, so the body text came out at 10px. Setting 16px on body fixed it. The share of legible text went from 5.39% to 100%, and the warning disappeared.

Note that this audit was removed in Lighthouse 13. The warning only appears up to Lighthouse 12.

Note

The test environment was Ubuntu 24.04 and Node.js 22.23.5. I installed Lighthouse 12.8.2, the last version with this audit, and the latest 13.6.0 from npm and ran them from the CLI. The browser was Google Chrome for Testing 158, specified with CHROME_PATH and run in headless mode. Unless noted otherwise, the results come from running only the "Best practices" category of 12.8.2 with the default mobile settings. I built the pages in the test environment and served them from 127.0.0.1 with a small server written in Node.js. I checked the wording of the Japanese report against Lighthouse's translation files. I did not try the Lighthouse panel in Chrome DevTools or PageSpeed Insights.

A page that became 10px because I forgot to set the body size

For the test, I made a page imitating a diary of cat observations. To make rem values easy to calculate, I set the html font size to 62.5% (10px, which is 62.5% of the browser default of 16px). I gave the headline and notes sizes in rem, but I did not set anything for the body text.

css
html { font-size: 62.5%; }
h1 { font-size: 2.4rem; }
.note, .date { font-size: 1rem; }

The body paragraphs inherited 10px from html, so everything except the 24px headline came out at 10px.

The table in the report shows which CSS rules make the text small

When I ran Lighthouse 12.8.2 on this page, a warning appeared in the "User Experience" section of Best Practices (the Japanese report uses a localized name for this section). Lighthouse's official documentation lists this as an SEO audit, but in the default config (default-config.js) for 12.8.2, it is included under Best Practices.

The Lighthouse report open at "Document doesn't use legible font sizes — 5.39% legible text". The table lists the html rule at bad.html:8:6 at 76.65% coverage and 10px, the .note, .date rule at bad.html:10:14 at 17.96% coverage and 10px, and Legible text at 5.39% for 12px or larger
The report for the page before the fix. The CSS rules that caused small text are listed in order of how much text they cover

The "Source" and "Selector" columns are the CSS rules that set the size of the small text. The first row points to line 8 of the HTML, where html { font-size: 62.5%; } is set. The body paragraphs have no size of their own, so they show the inherited html rule. "% of Page Text" (the Japanese report uses a localized column name) is the share of the page's text that this rule made small. The last row, "Legible text", is the share of text at 12px or larger. It is the same value as the "5.39% legible text" shown next to the audit name. The table lists rules from the largest share of text to the smallest.

I used a small script I wrote to pull the score and the font-size result from the JSON report. Here is the output. The source line numbers are zero-based, so each is one less than the number shown in the on-screen table.

text
best-practices score: 96  failed: font-size
[font-size] weight=1 group=best-practices-ux score=0 (binary)  displayValue=5.39% legible text  title: Document doesn't use legible font sizes
  source=bad.html:7:6  selector=html  coverage=76.65%  fontSize=10px
  source=bad.html:9:14  selector=.note, .date  coverage=17.96%  fontSize=10px
  source=Legible text  selector=-  coverage=5.39%  fontSize=≥ 12px

font-size was the only audit that failed, and the Best Practices score was 96.

Fix it by setting a font size on body

I set body to 1.6rem (16px). I also changed the date and note text from 1rem (10px) to 1.2rem (12px).

css
html { font-size: 62.5%; }
body { font-size: 1.6rem; }
h1 { font-size: 2.4rem; }
.note, .date { font-size: 1.2rem; }

Setting a size on body overrode the html rule that the body text had been inheriting (the first row in the table), so the 76.65% share was fixed. After the change, 100% of the text was legible, and the Best Practices score went back to 100.

text
best-practices score: 100  failed: (none)
[font-size] weight=1 group=best-practices-ux score=1 (binary)  displayValue=100% legible text  title: Document uses legible font sizes
  source=Legible text  selector=-  coverage=100.00%  fontSize=≥ 12px

Here is the comparison when the page is opened at a phone width (412px):

The same diary page at phone width, shown before and after the fix stacked vertically. Before the fix, all text except the headline is very small. After the fix, the body text is a comfortable size to read
Before (top) and after (bottom). The same page shown at phone width

Exactly 60% passes, 59% fails

The official documentation says that a page is flagged when 40% or more of its text is smaller than 12px. As a fix, it recommends making at least 60% of the page text 12px or larger. In the audit source (font-size.js), the audit passes when 60% or more of the text is 12px or larger. To check the boundary, I tested pages with different counts of 16px "cat" characters (a single kanji) and 11px "ne" characters (a single hiragana). I made sure each paragraph fit on one line.

Characters at 16px Characters at 11px Legible share Result
60 40 60% Pass
59 41 59% Fail

A page with exactly 40% small text passed. In 12.8.2, the audit fails when more than 40% of the text is small.

A paragraph that wraps is counted by line

Even with the same 60 and 40 characters, the result changed when each was in one paragraph that wrapped at phone width.

text
[font-size] weight=1 group=best-practices-ux score=1 (binary)  displayValue=69.23% legible text  title: Document uses legible font sizes
  source=wrap.html:7:34  selector=.small  coverage=30.77%  fontSize=11px
  source=Legible text  selector=-  coverage=69.23%  fontSize=≥ 12px

The gatherer (gatherers/seo/font-size.js) uses Chrome's DOMSnapshot.captureSnapshot to take each text box (textBox) that is drawn on screen and adds up the characters in each one. When I reproduced the same extraction with Playwright, the 16px paragraph wrapped to 3 lines and the 11px paragraph wrapped to 2 lines. Every line's box pointed to the text of the whole paragraph (60 characters and 40 characters).

text
== wrap.html  textBoxes=5
  16px len=60  "猫猫猫猫猫猫猫猫猫猫猫猫"…
  16px len=60  "猫猫猫猫猫猫猫猫猫猫猫猫"…
  16px len=60  "猫猫猫猫猫猫猫猫猫猫猫猫"…
  11px len=40  "ねねねねねねねねねねねね"…
  11px len=40  "ねねねねねねねねねねねね"…
  total=260 small=80 legible=69.23%

The total is 60×3 + 40×2 = 260 characters. (260 − 80) ÷ 260 gives 69.23%, which matches the Lighthouse value. In this test, a longer paragraph counted for more, in proportion to the number of lines it took up. The small text was really 40 of 100 characters, but the table showed 30.77%. The percentages in the table are not always a plain comparison of character counts on the page.

Pages without a viewport, and the desktop preset

I removed the <meta name="viewport"> tag from the page whose text I had enlarged and ran the audit again. font-size failed without showing a table, and the following explanation appeared.

text
best-practices score: 93  failed: viewport, font-size
[font-size] weight=1 group=best-practices-ux score=0 (binary)  displayValue=-  title: Document doesn't use legible font sizes  explanation: Text is illegible because there's no viewport meta tag optimized for mobile screens.

In the Japanese report, the explanation is a localized version of this same English text. In the audit source, if the viewport is not set up for mobile, the audit fails before it checks the text size. In that case, add <meta name="viewport" content="width=device-width, initial-scale=1"> inside <head> before changing any CSS.

On the other hand, with the desktop preset (--preset=desktop), font-size was marked as not applicable (notApplicable) and did not count toward the score, even for the original page with 10px text. This warning only appears when the audit is run with the mobile settings.

Also, 11px text hidden with visibility: hidden or display: none was not counted. A page with only 40 characters at 16px and 60 hidden characters at 11px had 100% legible text.

In Lighthouse 13, this audit does not appear

I ran Lighthouse 13.6.0 on the same original page with 10px text. Best Practices scored 100, and the report had no font-size audit.

text
== bad13  (Lighthouse 13.6.0, HeadlessChrome/158.0.0.0, formFactor mobile)
best-practices score: 100  failed: (none)
font-size: (no such audit in this report)  audits containing "font": (none)

The 13.0.0 release notes include "remove font-size audit", and the official documentation also says the audit was removed in Lighthouse 13.

A full score in Lighthouse 13 does not mean the text size has been fixed. Lighthouse 13 did not warn about the 10px body text on the original page. If you want to check against the 12px threshold, install version 12 with npm i -D lighthouse@12.8.2, as I did in this test, and run it.

​Posted by 86