日本語

Fixing Lighthouse “Background and foreground colors do not have a sufficient contrast ratio”

​​Lighthouse​Accessibility,CSS,Troubleshooting,WCAG

When the Lighthouse accessibility audit reports "Background and foreground colors do not have a sufficient contrast ratio." (the Japanese report shows the same message in Japanese), some elements have too little difference between the text color and the background color. For each element, the report shows the current contrast ratio and the required ratio (4.5:1 or 3:1). Make the text color darker (or the background lighter, or the reverse) until the gap closes, and the warning goes away. This warning often appears when dates or notes are set in light gray, or when white text sits on a light-colored button.

In my test environment, I ran Lighthouse on a page with light gray text and a light blue button, and confirmed that the warnings appear and disappear once the colors are fixed.

Note

The test environment was Ubuntu 24.04, Node.js 22.23.4, and Lighthouse 13.6.0 (the CLI installed with npm; the axe-core inside it is 4.14.0). The browser was Google Chrome for Testing 153 in headless mode. I ran only the accessibility category (--only-categories=accessibility) with the default mobile settings. I built the pages myself and served them from 127.0.0.1. For running axe-core directly and taking screenshots, I used Playwright 1.63.0. I did not test the Lighthouse panel in Chrome DevTools, PageSpeed Insights, fixing text placed over background images or gradients, or dark mode color schemes.

The page that triggers the warning

The page I used for testing is shown below. It has the same gray (#949494) text at 24px and at 16px, a date note in an even lighter #999999, and a button with white text on a light blue (#00c8e8) background.

html
<style>
  .note { color: #999999; font-size: 14px; }
  .lead { color: #949494; font-size: 24px; }
  .small { color: #949494; font-size: 16px; }
  .btn { color: #ffffff; background: #00c8e8; border: 0; padding: 8px 16px; font-size: 16px; }
</style>

<h1>猫の手帳</h1>
<p class="lead">今週のおすすめ</p>
<p class="small">今週のおすすめ</p>
<p class="note">最終更新:2026年11月13日</p>
<button class="btn" type="button">登録する</button>

The code above shows only the part of style and what is inside main (the other examples follow the same pattern). The body background is white (#ffffff). I served this page with python3 -m http.server 8000 --bind 127.0.0.1 --directory site and ran Lighthouse like this:

bash
npx lighthouse http://127.0.0.1:8000/bad.html \
  --only-categories=accessibility \
  --output=json --output=html --output-path=./out/bad \
  --chrome-flags="--headless=new --no-sandbox" --quiet

When I opened this warning in the HTML report, three elements were listed under "Failing Elements". The 24px "This week's picks" heading was not among them.

Screenshot of the Lighthouse report with the "Background and foreground colors do not have a sufficient contrast ratio." audit open. Under Failing Elements, three items are listed alongside a reduced image of the page: p.small with the text "This week's picks", p.note with the text "Last updated: November 13, 2026", and button with the text "Sign up". These labels are in Japanese in the image.
The report before the fix. The three flagged elements are listed.

Reading the numbers in the report

The list in the HTML report does not show which numbers are short. The JSON report includes a description for each element. I extracted it with a small Node.js script, and the output was as follows. The lines starting with accessibility score: and similar are headings added by my script. I left out lines such as the Lighthouse version and the score breakdown.

text
accessibility score: 90
color-contrast title: Background and foreground colors do not have a sufficient contrast ratio.
color-contrast score: 0 (binary)
- body > main > p.small | <p class="small"> | 今週のおすすめ
   Fix any of the following:
     Element has insufficient color contrast of 3.03 (foreground color: #949494, background color: #ffffff, font size: 12.0pt (16px), font weight: normal). Expected contrast ratio of 4.5:1
- body > main > p.note | <p class="note"> | 最終更新:2026年11月13日
   Fix any of the following:
     Element has insufficient color contrast of 2.84 (foreground color: #999999, background color: #ffffff, font size: 10.5pt (14px), font weight: normal). Expected contrast ratio of 4.5:1
- body > main > button.btn | <button class="btn" type="button"> | 登録する
   Fix any of the following:
     Element has insufficient color contrast of 2.01 (foreground color: #ffffff, background color: #00c8e8, font size: 12.0pt (16px), font weight: normal). Expected contrast ratio of 4.5:1
failed accessibility audits: color-contrast

For each element, there are four things to read:

  • contrast of 3.03: the current contrast ratio
  • foreground color and background color: the text and background colors used for the calculation
  • font size and font weight: the text size and weight used to determine the required ratio
  • Expected contrast ratio of 4.5:1: the ratio needed to pass

.lead (24px) and .small (16px) both use #949494, but the 24px version passed and only the 16px version was flagged. The required ratio depends on the text size. I check this in a later section.

Even with the Japanese report (--locale=ja), the audit name appeared in Japanese, but the per-element descriptions stayed in English.

Fixing it by darkening the text or background

The fix is to change the text color or the background color so the ratio reaches the value shown in "Expected contrast ratio." In this example, I changed the gray text to #767676 and the button background to a darker blue, #067a98.

css
.note { color: #767676; font-size: 14px; }
.small { color: #767676; font-size: 16px; }
.btn { color: #ffffff; background: #067a98; border: 0; padding: 8px 16px; font-size: 16px; }

The 24px .lead already passed, so I left it at #949494. When I ran Lighthouse again under the same conditions, the warning disappeared and the score became 100 (I left out the score breakdown lines):

text
accessibility score: 100
color-contrast title: Background and foreground colors have a sufficient contrast ratio
color-contrast score: 1 (binary)
failed accessibility audits: (none)

Lighthouse reports do not show the ratios of elements that pass. So I ran axe-core 4.14.0, the same version Lighthouse uses, directly in Playwright on the page, and also exported the ratios of the passing elements.

text
--- good.html
passes: h1 | ratio=14.66 fg=#1f2a30 bg=#ffffff size=24.0pt (32px) weight=bold expected=3:1
passes: .lead | ratio=3.03 fg=#949494 bg=#ffffff size=18.0pt (24px) weight=normal expected=3:1
passes: .small | ratio=4.54 fg=#767676 bg=#ffffff size=12.0pt (16px) weight=normal expected=4.5:1
passes: .note | ratio=4.54 fg=#767676 bg=#ffffff size=10.5pt (14px) weight=normal expected=4.5:1
passes: button | ratio=4.94 fg=#ffffff bg=#067a98 size=12.0pt (16px) weight=normal expected=4.5:1

On a white background, #767676 text gives 4.54:1, which is just above 4.5:1. For the button with white text, changing the background to #067a98 gives 4.94:1.

Screenshot of the page before and after the fix, stacked vertically. Before: the 16px "This week's picks" line and the date are light gray, and the "Sign up" button is light blue with white text. After: those two lines are a slightly darker gray, and the button is a darker blue with white text. The 24px "This week's picks" heading is the same gray in both. The labels are in Japanese in the image.
The page before (top) and after (bottom) the fix. Only the three flagged items had their colors changed.

If you want to keep white text, as on the button, darken the background. If you cannot change the background, darken the text color. Either change works, and the warning goes away once the ratio reaches the required value.

Large text passes at 3:1

The required ratio is 4.5:1 for normal text and 3:1 for large text. In axe-core 4.14.0's check settings, text is treated as large at 18pt or more, or at 14pt or more when bold (font-weight 700 or higher). In pixels, 18pt is 24px and 14pt is about 18.67px. This rule carries the wcag143 tag, which refers to WCAG success criterion 1.4.3.

I also checked the boundary for bold text on a separate page. It has bold #949494 text at 18px and at 19px.

html
<style>
  .bold18 { color: #949494; font-size: 18px; font-weight: bold; }
  .bold19 { color: #949494; font-size: 19px; font-weight: bold; }
</style>

<p class="bold18">太字18pxの見出し風の文字</p>
<p class="bold19">太字19pxの見出し風の文字</p>

The direct axe-core run gave the following. Both ratios are 3.03, but the required ratios differ (I left out the other element lines):

text
violations: .bold18 | ratio=3.03 fg=#949494 bg=#ffffff size=13.5pt (18px) weight=bold expected=4.5:1
passes: .bold19 | ratio=3.03 fg=#949494 bg=#ffffff size=14.3pt (19px) weight=bold expected=3:1

In the Lighthouse report too, only the 18px bold text was flagged, not the 19px one. Another option is to make the text slightly larger or bolder so it falls into the 3:1 group and passes.

Text faded with opacity is also flagged

Even if the text color itself is dark, the warning appears when the whole element is faded with opacity. I placed a paragraph with color: #1f2a30 and opacity: 0.4.

html
<style>
  .faded { color: #1f2a30; opacity: 0.4; }
</style>

<p class="faded">opacity で薄くした文字</p>

The Lighthouse result was as follows:

text
- body > main > p.faded | <p class="faded"> | opacity で薄くした文字
   Fix any of the following:
     Element has insufficient color contrast of 2.34 (foreground color: #a5aaac, background color: #ffffff, font size: 12.0pt (16px), font weight: normal). Expected contrast ratio of 4.5:1

The foreground color is not the #1f2a30 written in the CSS but #a5aaac, which is the result of blending with white. If the color in the report does not match anything in your CSS, check whether opacity is applied.

Text that is not flagged

A Lighthouse score of 100 does not guarantee that every text element has enough contrast. I added two more elements to the same page:

html
<style>
  .hero { background-image: linear-gradient(90deg, #00c8e8, #eefafd); padding: 16px; }
  .hero p { color: #ffffff; margin: 0; }
</style>

<div class="hero"><p>グラデーションの上の白い文字</p></div>
<button type="button" disabled>送信できません</button>

The white text on the gradient did not appear in the Lighthouse results. When I ran axe-core directly, this element was neither a pass nor a fail but "incomplete" (cannot be determined), with the reason bgGradient. The axe-core message reads "Element's background color could not be determined due to a background gradient", meaning the background is a gradient, so its color cannot be determined.

text
incomplete: div > p | ratio=0 fg=undefined bg=undefined size=12.0pt (16px) weight=normal expected=4.5:1 messageKey=bgGradient

In Lighthouse 13.6.0's code that scores axe-core results, the scored audit looks only at violations and does not count incomplete results. Text over background images, and text overlapped by other elements, are also listed as incomplete reasons in axe-core's message list. Check the colors of this kind of text yourself.

The button with disabled did not appear as a pass, fail, or incomplete. In axe-core 4.14.0's target selection code, disabled elements are excluded from the start.

Effect on the score

In Lighthouse 13.6.0's default configuration (default-config.js), the weight of color-contrast is 7. The audit scores 0 if there is at least one violation, so the score drops the same amount whether there is one flagged element or three. On the page I tested, the total weight was 71, and losing 7 gave 64 / 71, which is a score of 90.

After the fix, check whether the Failing Elements list is empty, rather than looking at the score. Elements that pass, such as one at 4.54:1 with #767676, do not appear in the Lighthouse report even when they are just above the threshold. If you want to see the ratio values, run axe-core directly as shown above.

​Posted by 86