日本語

Fixing Lighthouse’s “Links rely on color to be distinguishable” Warning for Links in Text

​​Lighthouse​Accessibility,CSS,Troubleshooting,WCAG

When Lighthouse's accessibility audit shows "Links rely on color to be distinguishable." (link-in-text-block), the links inside your text can be told apart from the surrounding text only by color. This warning usually appears on blog or site body text where the link underline is removed with text-decoration: none and the color difference between the link and the body text is small. Adding an underline, drawing a line with border-bottom or similar, or raising the contrast ratio between the link text and the body text to 3:1 or more clears the warning.

In a test environment, I ran Lighthouse on a page with underline-less links. I confirmed that the warning appeared, and that it went away after I applied the fixes.

Note

The test environment was Ubuntu 24.04, Node.js 22.23.5, and Lighthouse 13.6.0 (the CLI installed with npm; the bundled axe-core is 4.14.0). The browser was headless Google Chrome for Testing 158. I ran only the accessibility category (--only-categories=accessibility) with the default mobile settings. I built the pages locally and served them from 127.0.0.1. Japanese text was displayed with Noto Sans CJK JP. I did not test runs from the Lighthouse panel in Chrome DevTools or from PageSpeed Insights, and I did not test how the pages look with simulated color vision differences.

The page that triggers the warning

For the test, I used a page with body text in #333333, links in blue (#1a73e8), and no underline. The menu at the top has three links in the same color with no underline. (The <!doctype>, <head>, and <body> tags are omitted.)

html
<style>
body { font-family: "Noto Sans CJK JP", sans-serif; color: #333333; background: #ffffff; line-height: 1.8; margin: 16px; }
.menu { list-style: none; padding: 0; display: flex; gap: 16px; }
.menu a { color: #1a73e8; text-decoration: none; }
a { color: #1a73e8; text-decoration: none; }
</style>
<header>
<nav><ul class="menu"><li><a href="/">ホーム</a></li><li><a href="/notes/">メモ一覧</a></li><li><a href="/about/">このサイトについて</a></li></ul></nav>
</header>
<main>
<h1>画像の読み込みを速くする</h1>
<p>画像には <a href="/notes/width-height">width と height を書いておく</a>と、読み込み中にレイアウトがずれません。</p>
<p>形式は <a href="/notes/avif">AVIF や WebP</a> を使うと、ファイルが小さくなります。</p>
</main>
<footer>
<p>質問は<a href="/contact">お問い合わせ</a>から受け付けています。</p>
</footer>

I served this page with python3 -m http.server and ran Lighthouse like this. For the browser, I set the environment variable CHROME_PATH to the location of Chrome for Testing (for example, /path/to/chrome).

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

In the HTML report, the three links in the body text and the footer were listed under "Failing Elements." The three menu links were not listed.

Lighthouse report with the "Links rely on color to be distinguishable." audit opened. Three links, labeled in Japanese (meaning "Note width and height", "AVIF and WebP", and "Contact"), are listed under Failing Elements, along with the paragraphs that contain them
Report for the page before the fix. The three links in the body text are listed

From the JSON report, the accessibility score and the result of this audit are as follows. The three links fail for the same reason, so I show only the first one. The second-to-last line is the total weight of the audits that went into the score (passed / total).

text
accessibility score: 92
link-in-text-block title: Links rely on color to be distinguishable.
link-in-text-block score: 0 (binary)
- body > main > p > a | <a href="/notes/width-height">
   Fix any of the following:
     The link has insufficient color contrast of 2.8:1 with the surrounding text. (Minimum contrast is 3:1, link text: #1a73e8, surrounding text: #333333)
     The link has no styling (such as underline) to distinguish it from the surrounding text
weights (passed/total): 82 / 89
failed accessibility audits: link-in-text-block

In the Japanese report (--locale=ja), the audit name was a Japanese title that means "Links are distinguishable depending on color." It is a translation of the English "Links rely on color to be distinguishable.", and it has the same meaning: the links are distinguished only by color.

Conditions for clearing the warning

The two lines under "Fix any of the following" are the conditions for clearing the warning. Meeting either one is enough to pass.

  • The contrast ratio between the link text and the surrounding text is 3:1 or more.
  • A style such as an underline makes the link distinguishable from the surrounding text.

The rule is defined in axe-core's link-in-text-block rule, which Lighthouse uses internally. The rule is based on WCAG Success Criterion 1.4.1, "Use of Color." The 3:1 threshold for color difference matches the idea in W3C Technique G183: if links are distinguished from text only by color, the contrast ratio between the link and the surrounding text must be 3:1 or more.

The "style" check is defined in axe-core's element-is-distinct.js. It checks whether the link has a background image, a top or bottom border (border-top, border-bottom), or an outline. It also checks whether any of the following differ from the surrounding paragraph: font family, text-decoration-line, text-decoration-style, font-weight, font-style, or font-size.

The menu links were not flagged because axe-core only checks links that are inside text. The selection logic looks at the block that contains the link, such as a paragraph, and checks whether it has more non-link text than link text (is-in-text-block.js). A menu made up only of links falls outside this audit.

Three ways to fix it

Each of the following three changes cleared the warning. Each one changes a single line of CSS.

css
/* Fix 1: add an underline (text-underline-offset lowers the line slightly) */
a { color: #1a73e8; text-decoration: underline; text-underline-offset: 0.2em; }

/* Fix 2: draw a line with border-bottom instead of an underline */
a { color: #1a73e8; text-decoration: none; border-bottom: 1px solid currentColor; }

/* Fix 3: keep the link color, and change only body's color from #333333 to #000000 (other body rules stay the same) */
body { color: #000000; }
a { color: #1a73e8; text-decoration: none; }

I ran each page under the same conditions. All three gave the following result.

text
accessibility score: 100
link-in-text-block title: Links are distinguishable without relying on color.
link-in-text-block score: 1 (binary)
weights (passed/total): 89 / 89
failed accessibility audits: (none)

I took a screenshot of the first paragraph on each page. The results look like this.

Screenshots of the same paragraph from the page before the fix and the three fixed pages, stacked vertically. Before the fix and Fix 3 have no line under the link and differ only by color. Fix 1 and Fix 2 have a blue line under the link
From the top: before the fix, with an underline, with a border-bottom line, and with a darker body text color

For Fix 1, I added text-underline-offset to move the underline slightly away from the text.

Fix 3 meets the criterion using color difference alone. I calculated the contrast ratio between the link color #1a73e8 and the surrounding text using the WCAG formula. The results are below.

Surrounding text Ratio: link vs. surrounding text Ratio: link vs. background (white)
#333333 (before the fix) 2.80:1 4.51:1
#000000 (Fix 3) 4.66:1 4.51:1

The 2.80 before the fix is the same number as "2.8:1" in the report. When I made the body text black, the color difference went above 3:1.

However, this approach limits which color combinations you can use. The link text also has to be readable against the background. In Lighthouse's color-contrast audit (axe-core's color-contrast check), the threshold for normal-size text is 4.5:1. On top of that, the link must differ from the surrounding text by 3:1 or more. In my test, #333333 did not provide enough difference, so I changed the body text to #000000 and met the criteria. G183 also says that, because both colors must meet background contrast requirements in addition to the difference between link and text, choosing colors becomes harder. G183 also suggests adding another way to distinguish links, such as an underline or bold text, even when the contrast requirement is met.

Approaches that do not clear the warning, and approaches that clear it without changing how the page looks

I also tested the following three approaches.

css
/* Show the underline only on hover or keyboard focus */
a { color: #1a73e8; text-decoration: none; }
a:hover, a:focus-visible { text-decoration: underline; }

/* Set the font weight to 500 */
a { color: #1a73e8; text-decoration: none; font-weight: 500; }

/* Keep the underline, but make its color transparent */
a { color: #1a73e8; text-decoration: underline; text-decoration-color: transparent; }

The page that shows the underline only on hover kept the same score as before the fix, 92, and the same three links were flagged. The underline that appears with :hover or :focus-visible did not count as a reason to pass. From a reader's point of view, too, it stays unclear which text is a link until the mouse hovers over it.

The other two approaches both cleared the warning, and the score became 100. axe-core checks whether the font-weight or text-decoration-line values differ from the surrounding paragraph, so a different value passes.

However, the screenshots of these two pages were pixel-for-pixel identical to the page before the fix. I compared the SHA-1 hashes (first 12 characters) of PNG screenshots of the main element. The following four lines are from the page before the fix, the hover-only page, and these two pages. The hashes are the same for all four.

text
bad main sha1=02b87adc73f5 | rgb(26, 115, 232) none rgb(26, 115, 232) 400 none
hover-only main sha1=02b87adc73f5 | rgb(26, 115, 232) none rgb(26, 115, 232) 400 none
weight-500 main sha1=02b87adc73f5 | rgb(26, 115, 232) none rgb(26, 115, 232) 500 none
transparent-underline main sha1=02b87adc73f5 | rgb(26, 115, 232) underline rgba(0, 0, 0, 0) 400 none

The columns on the right are the link color, text-decoration-line, the underline color, font-weight, and border-bottom-style, as computed by the browser. The transparent underline has the value underline, but its line color is rgba(0, 0, 0, 0), so nothing appears on screen. For the weight 500, the Noto Sans CJK JP font installed in the test environment has only Regular (400) and Bold (700). So the text was rendered at the same weight as 400.

Warning

A score of 100 in Lighthouse does not guarantee that readers can tell the links apart visually. After you make a fix, open the page and check by eye whether the links stand out from the surrounding text.

How the score is affected

Lighthouse converts the axe-core results into a score for each audit. An audit gets 0 if there is a violation, and 1 if there is none. The accessibility score is the weighted average of these results. In the Lighthouse 13.6.0 default configuration, the weight of link-in-text-block is 7.

On the test page, the total weight of the audits that went into the score was 89. Before the fix, only the 7 for link-in-text-block was lost, so the score was 82 / 89, which rounds to 92. After the fix, the score was 89 / 89, which is 100. This audit is binary, meaning it scores either 0 or 1. As long as even one flagged link remains, the score stays at 0 for this audit.

​Posted by 86