日本語

Fixing Duplicate accesskey Values Reported by Lighthouse

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

When Lighthouse's accessibility audit reports "[accesskey] values are not unique", two or more elements on the page have the same accesskey value. To fix it, give each element a different character, or remove accesskey from the elements you don't need. (The Japanese version of the report shows the same message in Japanese.) This warning typically appears when the header and footer both contain the same link, and both have a keyboard shortcut (access key).

In my test environment, I ran Lighthouse on a page with overlapping accesskey values to see how the warning appears and what score it produces. I also pressed the keys in Chromium with the overlaps in place to see which element responds.

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. To check key behavior, I ran the same Chromium version with Playwright 1.63.0 and sent Alt-modified key presses through the Chrome DevTools Protocol. I ran only the accessibility category (--only-categories=accessibility), built the pages locally, and served them from 127.0.0.1. I did not test the Lighthouse panel in Chrome DevTools, PageSpeed Insights, browsers other than Chromium, or real keyboard and screen reader use.

A page with overlapping accesskey values, and the Lighthouse result

The test page is shown below. The header's Home link and the footer's Back to top link both use h. The header's Search link and the subscribe button use s and S. I also gave the hidden old contact link the same c as the header's Contact link.

html
<header>
  <nav>
    <a href="/" accesskey="h">ホーム</a>
    <a href="/search" accesskey="s">検索</a>
    <a href="/contact" accesskey="c">お問い合わせ</a>
  </nav>
</header>
<main>
  <h1>お知らせ</h1>
  <form action="/subscribe">
    <label for="mail">メールアドレス</label>
    <input type="email" id="mail" name="mail">
    <button type="submit" accesskey="S">登録</button>
  </form>
  <div hidden>
    <a href="/old-contact" accesskey="c">古いお問い合わせ</a>
  </div>
</main>
<footer>
  <a href="/" accesskey="h">トップへ戻る</a>
</footer>

I served this page with python3 -m http.server and ran Lighthouse as follows:

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 accessibility score was 93. In the HTML report, the NAVIGATION section shows a red triangle with "[accesskey] values are not unique". When you expand it, each overlapping pair is listed, with the earlier element followed by the later element that has the same value.

Lighthouse HTML report showing an accessibility score of 93. Under NAVIGATION, the "[accesskey] values are not unique" item is expanded. It lists the Home link followed by the Back to top link, and the Search link followed by the subscribe button. (The link texts in the image are in Japanese.)
Report for a page with three overlapping pairs of accesskeys. The score is 93, and the audit flags two pairs: h and s.

I extracted the score and audit results from the JSON report with a small script I wrote. In the output below, related is the later element that has the same value:

text
accessibility score: 93
[accesskeys] scoreDisplayMode=binary score=0 weight=7
title: `[accesskey]` values are not unique
- body > header > nav > a | <a href="/" accesskey="h">
   Fix all of the following:
     Document has multiple elements with the same accesskey
   related: <a href="/" accesskey="h"> "トップへ戻る"
- body > header > nav > a | <a href="/search" accesskey="s">
   Fix all of the following:
     Document has multiple elements with the same accesskey
   related: <button type="submit" accesskey="S"> "登録"
failed (binary) audits: accesskeys

The audit ID is accesskeys. It is scored as pass or fail (binary), and in the Lighthouse 13.6.0 default configuration it has a weight of 7. This was the only audit that failed, and it lowered the score from 100 to 93.

Uppercase and lowercase count as the same key, and hidden elements are ignored

The warning flagged only the two pairs h and s. The c pair was not flagged. This comes from how axe-core, which Lighthouse uses internally, makes its decision.

The axe-core check logic converts accesskey values to uppercase with toUpperCase() before comparing them. As a result, s and S count as the same key. Changing only one of them to uppercase does not fix the warning.

The code that collects the values skips elements that no user can see, such as those hidden with hidden. That is why the c on the hidden link was not counted.

With overlaps, Chromium activates only the later element

On the overlapping page, I sent Alt-modified key presses to Chromium and recorded which element was clicked. (I stopped link navigation and form submission.)

text
Alt+h: clicked=[トップへ戻る]
Alt+s: clicked=[登録]
Alt+c: clicked=[古いお問い合わせ]
Alt+r: clicked=[]

For every key, the element that responded was the later one on the page. h activated the footer's Back to top link, not the header's Home link. s activated the subscribe button, not the header's Search link. r activated nothing, because I had not assigned it to any element on this page.

On a separate page with two buttons that shared the same value, I sent Alt+h three times in a row. Each time, the later button was clicked and received focus. Pressing the key again never moved the activation back to the earlier button.

text
Alt+h: onclick=[ボタン2(h)] focus=ボタン2
Alt+h: onclick=[ボタン2(h)] focus=ボタン2
Alt+h: onclick=[ボタン2(h)] focus=ボタン2
Warning

For the c pair, which Lighthouse did not flag, the key activated the hidden Old contact link. When I sent Alt+c without stopping navigation, the page moved to /old-contact. Lighthouse does not report a hidden element that takes a key, so you need to find and remove its accesskey yourself.

I also tried sending the key with Playwright's page.keyboard.press('Alt+h'). In that case, nothing responded. Sending the key with Input.dispatchKeyEvent in the Chrome DevTools Protocol, with a text value, did work. In the code below, ch is the character to send, cdp is a session created with Playwright's newCDPSession, and modifiers: 1 means Alt is held down.

js
const k = { modifiers: 1, key: ch, code: 'Key' + ch.toUpperCase(), windowsVirtualKeyCode: ch.toUpperCase().charCodeAt(0) };
await cdp.send('Input.dispatchKeyEvent', { type: 'keyDown', ...k, text: ch, unmodifiedText: ch });
await cdp.send('Input.dispatchKeyEvent', { type: 'keyUp', ...k });

Give each value its own letter, or remove accesskey

To fix the warning, change one of the values you want to keep to a different letter. Changing only the case is not enough. If two links go to the same place, remove accesskey from one of them. In my test, I fixed the three places below (- marks the line before the fix, + the line after):

diff
-    <button type="submit" accesskey="S">登録</button>
+    <button type="submit" accesskey="r">登録</button>

-    <a href="/old-contact" accesskey="c">古いお問い合わせ</a>
+    <a href="/old-contact">古いお問い合わせ</a>

-  <a href="/" accesskey="h">トップへ戻る</a>
+  <a href="/">トップへ戻る</a>

I changed the subscribe button to r. The footer's Back to top link goes to the same page as the header's Home link, so I removed its accesskey. I also removed the one from the hidden link, even though Lighthouse did not report it.

When I ran Lighthouse under the same conditions on the fixed page, the audit passed and the score returned to 100:

text
accessibility score: 100
[accesskeys] scoreDisplayMode=binary score=1 weight=7
title: `[accesskey]` values are unique
failed (binary) audits: (none)

When I sent the keys the same way, each one activated the element I intended:

text
Alt+h: clicked=[ホーム]
Alt+s: clicked=[検索]
Alt+c: clicked=[お問い合わせ]
Alt+r: clicked=[登録]

If you don't need access keys at all, removing all of them is another valid fix. MDN's description of the accesskey attribute notes that access keys can conflict with browser and assistive technology shortcuts, and that users may not notice they exist. It recommends not using them on typical websites and web apps. If no element has an accesskey, this audit is marked not applicable and the warning does not appear.

​Posted by 86