日本語

“Lighthouse label-content-name-mismatch: Fixing Buttons Whose aria-label Differs From Visible Text”

​​Lighthouse​Accessibility,axe-core,HTML,Troubleshooting

If the Lighthouse JSON report marks label-content-name-mismatch as failed (the English title is "Elements with visible text labels do not have matching accessible names."), the aria-label or aria-labelledby name on a button or link does not contain the text that is visible on screen. The warning goes away when you remove aria-label so the visible text becomes the name, or when you include the visible text as-is in the name. This warning appears when, for example, a "Send" button has an aria-label that says something different, or a "proceed to checkout" link has a different description in its aria-label.

I ran Lighthouse on a test page with buttons and links whose visible text and names differ. The warning appeared, and it went away after I fixed the names. I also found that in Lighthouse 13.6.0 this audit is not shown in the HTML report and does not affect the score.

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), with Playwright 1.63.0 and headless Google Chrome for Testing 153. I ran only the accessibility category (--only-categories=accessibility) with the default mobile settings. I wrote the pages myself and served them from 127.0.0.1. I did not test the Lighthouse panel in Chrome DevTools, PageSpeed Insights, or actual operation with a screen reader or voice input.

This audit does not appear in the HTML report

First, a note on where to find the result. In Lighthouse 13.6.0's config file, this audit has weight 0 and belongs to the hidden group. The comment on that line says "experimental".

text
585:        {id: 'label-content-name-mismatch', weight: 0, group: 'hidden'}, // Serious, experimental

The HTML report generator skips audits in the hidden group when it displays results. In my test, I opened the HTML report for a page that triggered the warning with Playwright. The 73 audits shown did not include label-content-name-mismatch, and the accessibility score stayed at 100.

The check itself still runs every time, and its result is stored in the JSON report under audits['label-content-name-mismatch']. The results in this article were extracted from the JSON with the following script. The Lighthouse CLI writes JSON when you pass --output=json.

js
// summary.mjs (lines that print the score and weight are omitted)
import fs from 'node:fs';
const r = JSON.parse(fs.readFileSync(process.argv[2], 'utf8'));
const a = r.audits['label-content-name-mismatch'];
console.log('title:', a.title);
console.log('score:', a.score, 'scoreDisplayMode:', a.scoreDisplayMode);
for (const it of a.details?.items ?? []) {
  console.log('-', it.node.selector, '|', it.node.snippet);
  console.log('  ', it.node.explanation.replace(/\n/g, '\n   '));
}

With the Japanese report (--locale=ja), the title is translated into Japanese. It has the same meaning as the English title.

A page that triggers the audit

The test page had three elements. In each one, the visible text and the name set with aria-label or similar differ.

html
<!-- 1. Visible text is Send, aria-label is different wording -->
<button type="button" class="send" aria-label="フォームを送る">送信</button>
<!-- 2. The link text and aria-label differ -->
<a href="/checkout" class="checkout" aria-label="カートを見る">購入手続きへ</a>
<!-- 3. aria-labelledby takes the name from another element's text -->
<span id="save-label" hidden>メモを保管</span>
<button type="button" class="save" aria-labelledby="save-label">保存</button>

I served this page with python3 -m http.server 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

The results extracted from the JSON are below. All three elements were flagged, yet the accessibility score was still 100.

text
accessibility score: 100
label-content-name-mismatch weight: 0 group: hidden
title: Elements with visible text labels do not have matching accessible names.
score: 0 scoreDisplayMode: binary
- body > main > button.send | <button type="button" class="send" aria-label="フォームを送る">
   Fix any of the following:
     Text inside the element is not included in the accessible name
- body > main > a.checkout | <a href="/checkout" class="checkout" aria-label="カートを見る">
   Fix any of the following:
     Text inside the element is not included in the accessible name
- body > main > button.save | <button type="button" class="save" aria-labelledby="save-label">
   Fix any of the following:
     Text inside the element is not included in the accessible name
failed accessibility audits: label-content-name-mismatch(weight 0)

The reason, "Text inside the element is not included in the accessible name", means that the text inside the element is missing from its accessible name. I used Playwright's ariaSnapshot() to dump the page structure. The button's name was "send the form" (translated from the Japanese aria-label), not the visible "Send".

text
- main:
  - heading "メモの編集" [level=1]
  - button "フォームを送る": 送信
  - link "カートを見る":
    - /url: /checkout
    - text: 購入手続きへ
  - button "メモを保管": 保存

This check comes from the label-content-name-mismatch rule in axe-core, which Lighthouse uses internally. As the wcag253 tag shows, it maps to WCAG 2.1 success criterion 2.5.3 (Label in Name). The Lighthouse description says that when the visible text and the name do not match, people using screen readers may get confused.

Fixing it by putting the visible text in the name

The warning goes away when the visible text appears in the name.

Diagram comparing the visible text with the accessible name. Top: a button showing Send has an aria-label that does not include the word Send, so it is flagged. Bottom: a link showing "proceed to checkout" has an aria-label that starts with the visible text and adds a word, so it passes. (The labels in this image are in Japanese.)
It passes when the visible text is included as-is in the name

The simplest fix is to remove aria-label or aria-labelledby so the visible text becomes the name. If you want to keep aria-label, include the visible text as-is in it. If you want to add more to the name, you can skip aria-label and append text that is visually hidden inside the button.

html
<!-- 1. Remove aria-label so the visible text becomes the name -->
<button type="button" class="send">送信</button>
<!-- 2. Make aria-label start with the visible text -->
<a href="/checkout" class="checkout" aria-label="購入手続きへ進む">購入手続きへ</a>
<!-- 3. Add supplementary text, hidden visually, after the visible text -->
<button type="button" class="save">保存<span class="visually-hidden">(メモ1)</span></button>

visually-hidden is a CSS class that shrinks the text into a 1-pixel box so that it is not visible on screen.

css
.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

When I ran Lighthouse again under the same conditions, the audit passed.

text
accessibility score: 100
label-content-name-mismatch weight: 0 group: hidden
title: Elements with visible text labels have matching accessible names.
score: 1 scoreDisplayMode: binary
failed accessibility audits: (none)

The names in ariaSnapshot() were "Send", "Proceed to checkout", and "Save (memo 1)" (translated from the Japanese text in the snapshot).

text
- main:
  - heading "メモの編集" [level=1]
  - button "送信"
  - link "購入手続きへ進む":
    - /url: /checkout
    - text: 購入手続きへ
  - button "保存 (メモ1)"

When I ran axe-core directly on the page with only this rule enabled, only the link counted as a pass. The Send and Save buttons have neither aria-label nor aria-labelledby, so they fall outside the rule's scope. The rule applies to elements whose name comes from their content, such as buttons and links, that have visible text and also have aria-label or aria-labelledby.

Names that contain the visible text elsewhere also pass

I also tested cases where the visible text is not at the start of the name, and cases where the visible text is only a symbol.

html
<button type="button" class="send" aria-label="フォームを送信">送信</button>
<button type="button" class="save" aria-label="上書き保存済みにする">保存</button>
<button type="button" class="close" aria-label="閉じる">×</button>
<button type="button" class="next" aria-label="Next page">Next</button>
<button type="button" class="prev" aria-label="Go back">Previous</button>

In the Lighthouse JSON, only the button that displayed "Previous" with aria-label="Go back" was flagged.

text
- body > main > button.prev | <button type="button" class="prev" aria-label="Go back">
   Fix any of the following:
     Text inside the element is not included in the accessible name

When I ran axe-core directly, the other four had the following results:

text
incomplete .close | <button type="button" class="close" aria-label="閉じる">×</button>
passes     .send | <button type="button" class="send" aria-label="フォームを送信">送信</button>
passes     .save | <button type="button" class="save" aria-label="上書き保存済みにする">保存</button>
passes     .next | <button type="button" class="next" aria-label="Next page">Next</button>

The visible text passed even though it is not at the start of the name. For example, the Send button's name ends with the word "send" in the middle of a longer phrase. axe-core's evaluation logic lowercases both the visible text and the name, splits them into words with the browser's Intl.Segmenter, and checks whether the sequence of visible words appears in the name. In the same Chrome, Intl.Segmenter split the Save button's name (which means "mark as overwritten and saved") into five words: "overwrite", "save", "done", a particle, and "do". Since "save" is extracted as its own word, it passes. Before comparing, the logic also removes parenthetical text, including full-width parentheses, from both the visible text and the name.

A single-symbol visible label such as "×" cannot be judged, so it was reported as "incomplete" and did not appear in Lighthouse's warnings.

The ACT rule for 2.5.3 gives a reason for removing parenthetical text: people who use voice input often do not say the words inside parentheses. When you write a name, the safest approach is to keep the words on screen as they are and include them unchanged in the name.

​Posted by 86