日本語

How to Fix the Lighthouse “image-redundant-alt” Warning

​​Lighthouse​Accessibility,HTML

When Lighthouse's accessibility audit reports that an image's alt is the same as the text around it, the link or button that contains the image already has that same text. The text already conveys the content, so setting the image to alt="" clears the warning and stops screen readers from reading the same words twice. This warning shows up for components that place an image next to text, such as a thumbnail in an article list link, a magnifying-glass icon next to the word "Search" in a button, or a photo next to a name in a list.

On the page I tested, Lighthouse flagged four images. After I set all four to alt="", this audit showed as "not applicable." The score was 100 both before and after the change. Because this audit does not affect the score, you will not notice it if you only look at the score.

Note

The test environment was Ubuntu 24.04, Node.js 22, and Lighthouse 13.6.0 (the npm package; the axe-core it uses internally is 4.14.0). I pointed Lighthouse at Chrome for Testing 158, which ships with Playwright 1.63.0, using the CHROME_PATH environment variable. I ran Lighthouse from the command line with the default mobile settings and only the accessibility category. The test page was served from a server I ran in the test environment (localhost:8080). The screen reader output is the name as reported by Playwright's ariaSnapshot(), not the output of an actual screen reader. I did not test the Lighthouse panel in Chrome DevTools or PageSpeed Insights.

The flagged page and Lighthouse output

I tested a page with images in three places. In each case, the image's alt matches the text right next to it.

html
<h2>新しい記事</h2>
<a href="/notes/1"><img src="cat.svg" width="120" height="80" alt="窓辺の猫">窓辺の猫</a>
<h2>サイト内検索</h2>
<form action="/search"><input type="search" name="q" aria-label="キーワード"><button type="submit"><img src="icon.svg" width="20" height="20" alt="検索">検索</button></form>
<h2>うちの猫</h2>
<ul><li><img src="cat.svg" width="60" height="40" alt="たま">たま</li><li><img src="cat.svg" width="60" height="40" alt="みけ">みけ</li></ul>

I ran Lighthouse on this page, then used a small script (summarize.mjs) to pull this audit out of the JSON results.

console
$ npx lighthouse http://localhost:8080/before.html --only-categories=accessibility --output=json --output=html --output-path=./out/before --chrome-flags="--headless=new --no-sandbox" --quiet
$ node summarize.mjs out/before.report.json
lighthouseVersion: 13.6.0  formFactor: mobile  locale: en-US
requestedUrl: http://localhost:8080/before.html
accessibility score: 100
image-redundant-alt: score=1 scoreDisplayMode=informative title="Image elements do not have `[alt]` attributes that are redundant text."
  <img src="cat.svg" width="120" height="80" alt="窓辺の猫"> | body > main > a > img | Fix all of the following: Element contains <img> element with alt text that duplicates existing text
  <img src="icon.svg" width="20" height="20" alt="検索"> | main > form > button > img | Fix all of the following: Element contains <img> element with alt text that duplicates existing text
  <img src="cat.svg" width="60" height="40" alt="たま"> | main > ul > li > img | Fix all of the following: Element contains <img> element with alt text that duplicates existing text
  <img src="cat.svg" width="60" height="40" alt="みけ"> | main > ul > li > img | Fix all of the following: Element contains <img> element with alt text that duplicates existing text

(In practice I ran this from a small shell script after setting CHROME_PATH. I left out the exit code line and the results for other audits.)

image-redundant-alt is the audit in question. It lists four images, but score=1, and the title is "Image elements do not have [alt] attributes that are redundant text.", which is the passing wording. Lighthouse 13.6.0's source for this audit also contains the failing title "Image elements have [alt] attributes that are redundant text.", but I did not see it in my tests. With --locale=ja, the title is the Japanese passing text, which is also the passing wording. The title alone makes it look like there is no problem, so open the audit and check whether images are listed.

In the HTML report, this audit appears under "Names and labels" with a gray circle and "Unscored." When you expand it, the four images are listed under "Failing Elements."

The Lighthouse report with the Image elements do not have alt attributes that are redundant text audit expanded. The description ends with Unscored, and under Failing Elements, four img elements are listed with alt="cat by the window", alt="search", alt="Tama", and alt="Mike" (these alt texts are in Japanese), each with a small image showing its position on the page
The report for the page before the fix. The title still shows the passing wording, but the four images are listed

According to the audit's description, alt text that duplicates the text of a link or the text right next to an image can cause screen readers to read it twice, which confuses users. In Playwright's ariaSnapshot(), the link name came out as the alt text followed directly by the link text, so the Japanese for "cat by the window" appeared twice in a row. The button name was the Japanese for "search" repeated twice.

text
  - link "窓辺の猫窓辺の猫":
    - /url: /notes/1
    - img "窓辺の猫"
    - text: 窓辺の猫
  - heading "サイト内検索" [level=2]
  - searchbox "キーワード"
  - button "検索検索":
    - img "検索"
    - text: 検索

Fixing it with alt=""

I changed the alt on all four images to alt="". I did not remove the alt attribute. I kept it and set its value to empty.

html
<a href="/notes/1"><img src="cat.svg" width="120" height="80" alt="">窓辺の猫</a>
<button type="submit"><img src="icon.svg" width="20" height="20" alt="">検索</button>
<ul><li><img src="cat.svg" width="60" height="40" alt="">たま</li><li><img src="cat.svg" width="60" height="40" alt="">みけ</li></ul>

Here are the results for the fixed page (only the relevant lines are shown):

console
accessibility score: 100
image-redundant-alt: score=null scoreDisplayMode=notApplicable title="Image elements do not have `[alt]` attributes that are redundant text."

This audit now shows as "not applicable" (notApplicable). image-alt, which checks whether images have an alt attribute, still passes. In ariaSnapshot(), the link name is now just the Japanese for "cat by the window," and the button name is just the Japanese for "search." The image (img) lines are gone from the output.

text
  - link "窓辺の猫":
    - /url: /notes/1
  - heading "サイト内検索" [level=2]
  - searchbox "キーワード"
  - button "検索"

According to MDN's explanation of the img element, alt="" marks the image as not essential content (for example, decoration), and it means the image may be omitted in non-visual environments, where the screen is not being looked at. An image that only repeats the adjacent text falls into this case.

Warning

Use alt="" only when the link or button contains text. In an image-only link (<a href="/notes/1"><img … alt=""></a>), the link-name audit (weight 7) fails with "Links do not have a discernible name," and the score dropped to 91. ariaSnapshot() also showed that the link had no name.

When you want to describe the photo, use an alt that differs from the text

If a thumbnail photo has information that the link text lacks, you can write what the photo shows in alt instead of leaving it empty. Changing it to alt="a white cat curled up asleep by the window" made this audit "not applicable."

However, the link name becomes the photo description joined with the link text, so it reads as "a white cat curled up asleep by the window" followed directly by "cat by the window." The link name gets longer, and the photo description is read before the article title. Decide whether the photo description is really needed.

What counts as "the same"

The basis for the check is axe-core's image-redundant-alt rule and the check that compares the text it uses. The check looks for the nearest button, element with role="button", a with href, p, li, td, or th around the image. It then compares the image's name with all the text that reaches a screen reader inside that element. The comparison is case-insensitive.

I made one page per variation and ran Lighthouse on each. All of them scored 100.

Image and text pattern Result for this audit
alt="Tama" and link text tama Flagged
Whitespace added before and after the link text Flagged
Link text wrapped in <span> Flagged
Table cell (<td>) with an image alt="Sunny" and the text Sunny Flagged
Link text "Read the article about the cat by the window" Not applicable
Paragraph text "Tama. Sleeping by the window today." Not applicable
<figure> with a <figcaption> that matches alt Not applicable
<div> containing an image and an <h2> with the same text Not applicable
Image with role="presentation" Not applicable
Image with aria-hidden="true" Not applicable
Link text hidden with display:none Not applicable

The check compares the full text inside the containing element, so when there is more text, such as "Read the article about the cat by the window," it does not flag the image even if the alt words are included. On the other hand, differences in case, surrounding whitespace, and wrapping the text in <span> did not stop the warning.

A <figcaption> in a <figure>, or a heading in a <div>-based card, is not an element the check looks at, so it does not flag the same text. Still, in ariaSnapshot(), the figure page gave the figure itself the same name as the image, and the image and the caption both read the Japanese for "cat by the window" inside it. The div card page had an image and a heading with that same name. Two identical phrases are read in the same way as with links and buttons, so if a card's image and heading use the same words, consider alt="" even if this audit does not flag it.

role="presentation" and aria-hidden="true" also cleared the warning. In ariaSnapshot(), the link name was the Japanese for "cat by the window" on both pages, and there was no image line. However, both approaches keep the text in alt and only keep the image out of the name. If you want the image to be ignored, alt="" expresses that intent more clearly to someone reading the HTML.

​Posted by 86