Test cases: 12 passing, 23 failing (35 total)
This page contains various image elements to test accessible name computation according to WCAG guidelines.
This image has descriptive alt text that explains its content.
<img id="img-alt-descriptive-pass" src="..." alt="Mountain landscape with a lake and sun in the sky">
This decorative image correctly uses empty alt text to be ignored by screen readers.
<img id="img-alt-empty-decorative-pass" src="..." alt="">
This image uses aria-label instead of alt text for its accessible name.
<img id="img-aria-label-pass" src="..." aria-label="Green circle on gray background">
This image uses aria-labelledby to reference text elsewhere on the page for its accessible name.
<h4 id="chart-description">Quarter 1 Sales Performance Chart</h4>
<img id="img-aria-labelledby-pass" src="..." aria-labelledby="chart-description">
This complex chart image has appropriate alt text and references a longer description for screen reader users.
This line chart shows temperature trends from 2020 to 2023. The red line represents maximum temperatures, showing an upward trend with peaks in summer months. The blue line represents minimum temperatures, which follow a similar pattern but with less dramatic fluctuations.
<img id="img-complex-pass" src="..." alt="Temperature trends 2020-2023" aria-describedby="chart-long-desc">
<p id="chart-long-desc">This line chart shows temperature trends...</p>
This image is missing the alt attribute entirely.
<img id="img-no-alt-fail" src="...">
This image uses its filename as alt text, which is not descriptive.
<img id="img-filename-alt-fail" src="..." alt="image001.jpg">
This image has generic alt text that doesn't describe its content.
<img id="img-generic-alt-fail" src="..." alt="Image">
This image has redundant alt text that begins with "Image of" (unnecessary since screen readers already announce it's an image).
<img id="img-redundant-alt-fail" src="..." alt="Image of a blue rectangle">
This image has only whitespace in its alt attribute, which is treated differently than empty alt text.
<img id="img-whitespace-alt-fail" src="..." alt=" ">
This image has only punctuation in its alt text, which may not be announced by some screen readers.
<img id="img-punctuation-alt-fail" src="..." alt="...">
This inline SVG image has role="img" but lacks accessible name via title or aria attributes.
<svg id="svg-no-title-fail" width="200" height="150" xmlns="http://www.w3.org/2000/svg" role="img">
<rect width="200" height="150" fill="#f2f2f2" />
<rect x="25" y="50" width="150" height="50" fill="#b3e6b3" />
</svg>
This image has an aria-labelledby attribute pointing to an ID that doesn't exist.
<img id="img-broken-labelledby-fail" src="..." aria-labelledby="non-existent-id">
This inline SVG has role="img" and an empty title element, which doesn't provide an accessible name.
<svg id="svg-empty-title-fail" width="200" height="150" xmlns="http://www.w3.org/2000/svg" role="img">
<title></title>
<rect width="200" height="150" fill="#f2f2f2" />
<circle cx="100" cy="75" r="50" fill="#ffcc99" />
</svg>
This inline SVG has role="img" with a title element containing HTML markup. Screen readers will announce the literal tags, not interpret them.
<svg id="svg-html-title-fail" width="200" height="150" xmlns="http://www.w3.org/2000/svg" role="img">
<title>A <span lang="fr">Bonjour</span> greeting icon</title>
<rect width="200" height="150" fill="#f2f2f2" />
<text x="60" y="90" font-family="Arial" font-size="24" fill="#000">Bonjour</text>
</svg>
This inline SVG has role="img" and a title element containing only whitespace, which doesn't provide a proper accessible name.
<svg id="svg-whitespace-title-fail" width="200" height="150" xmlns="http://www.w3.org/2000/svg" role="img">
<title> </title>
<rect width="200" height="150" fill="#f2f2f2" />
<circle cx="100" cy="75" r="50" fill="#ccffcc" />
</svg>
This image contains HTML notation in its alt text, which won't render correctly for screen readers.
<img id="img-html-alt-fail" src="..." alt="<strong>Medical cross</strong> symbol">
This image incorrectly attempts to specify language within the alt text using HTML notation.
<img id="img-lang-alt-fail" src="..." alt="French greeting <span lang='fr'>Bonjour</span> on yellow background">
This image incorrectly uses HTML in its alt text, which won't be interpreted by screen readers. HTML tags in alt text are read literally.
<img id="img-html-foreign-alt-fail" src="..." alt="A sign saying <span lang='fr'>Bonjour</span>">
The following examples demonstrate specific edge cases and best practices for image accessibility.
This image correctly references a span with lang attribute using aria-labelledby to specify foreign language content.
<span id="french-greeting" lang="fr" aria-label="Bonjour"></span>
<img id="img-proper-lang-pass" src="..." aria-labelledby="french-greeting" alt="">
The following examples test special cases for SVG images.
This inline SVG includes a title element to provide an accessible name.
<svg id="svg-with-title-pass" width="200" height="150" xmlns="http://www.w3.org/2000/svg" role="img">
<title>Three colorful circles in a row</title>
<rect width="200" height="150" fill="#f2f2f2" />
<circle cx="50" cy="75" r="25" fill="#ff9999" />...
</svg>
This inline SVG uses aria-label to provide an accessible name.
<svg id="svg-with-aria-label-pass" width="200" height="150" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="Blue star on light background">
<rect width="200" height="150" fill="#f2f2f2" />
<path d="M100,30 L115,75 L165,75 L125,100 L140,150 L100,120 L60,150 L75,100 L35,75 L85,75 Z" fill="#4d94ff" />
</svg>
This decorative inline SVG correctly uses role="presentation" to be ignored by screen readers.
<svg id="svg-decorative-pass" width="200" height="20" xmlns="http://www.w3.org/2000/svg" role="presentation">
<rect width="200" height="20" fill="#ddd" />
</svg>
The following examples test accessible names for complex images created with non-image elements.
This div with role="img" uses aria-label to provide an accessible name for a complex weather widget.
<div id="weather-aria-label-pass" role="img" aria-label="Current weather: 72°F, Partly Cloudy" class="weather-container">
<div class="weather-icon">
<div class="sun"></div>
<div class="cloud"></div>
</div>
<div class="temperature">72°F</div>
<div class="condition">Partly Cloudy</div>
</div>
This complex chart element uses aria-labelledby to reference its accessible name.
<h4 id="sales-chart-title">Quarterly Sales Performance (in thousands)</h4>
<div id="chart-aria-labelledby-pass" role="img" aria-labelledby="sales-chart-title" class="chart-container">
<div class="bar-1"></div>
<div class="bar-2"></div>
<div class="bar-3"></div>
<div class="bar-4"></div>
<div class="chart-label">Q1-Q4</div>
</div>
This div with role="img" uses aria-label to provide an accessible name for a star rating display.
<div id="rating-aria-label-pass" role="img" aria-label="Rating: 4 out of 5 stars" class="rating-container">
<span class="star">★</span></span>
<span class="star">★</span></span>
<span class="star">★</span></span>
<span class="star">★</span></span>
<span class="star">☆</span></span>
</div>
This div with role="img" has no accessible name (missing aria-label or aria-labelledby).
<div id="weather-no-name-fail" role="img" class="weather-container">
<div class="weather-icon">...</div>
<div class="temperature">68°F</div>
<div class="condition">Partly Cloudy</div>
</div>
This complex chart has an empty aria-label, providing no accessible name.
<div id="chart-empty-label-fail" role="img" aria-label="" class="chart-container">
<div class="bar-1"></div>...
<div class="chart-label">Q1-Q4</div>
</div>
This div with role="img" has an aria-label containing only whitespace.
<div id="rating-whitespace-label-fail" role="img" aria-label=" " class="rating-container">
<span class="star">★</span></span>...
</div>
This complex chart references a non-existent element with aria-labelledby.
<div id="chart-broken-labelledby-fail" role="img" aria-labelledby="non-existent-chart-title" class="chart-container">
<div class="bar-1"></div>...
<div class="chart-label">Q1-Q4</div>
</div>
This div with role="img" uses a URL as its aria-label, which is not descriptive.
<div id="weather-url-label-fail" role="img" aria-label="https://example.com/weather-icon.png" class="weather-container">
<div class="weather-icon">...</div>
<div class="temperature">75°F</div>
<div class="condition">Partly Cloudy</div>
</div>
This div with role="img" incorrectly uses HTML markup in its aria-label. Screen readers will announce the literal HTML tags, not interpret them.
<div id="weather-html-label-fail" role="img" aria-label="Weather in <span lang='fr'>Paris</span>: Sunny, 28°C" class="weather-container">
<div class="weather-icon">...</div>
<div class="temperature">28°C</div>
<div class="condition">Sunny</div>
</div>
This div with role="img" has a generic, non-descriptive aria-label.
<div id="rating-generic-label-fail" role="img" aria-label="image" class="rating-container">
<span class="star">★</span></span>...
</div>
This div with role="img" has an aria-label containing only punctuation.
<div id="chart-punctuation-label-fail" role="img" aria-label="..." class="chart-container">
<div class="bar-1"></div>...
<div class="chart-label">Q1-Q4</div>
</div>
This div with role="img" uses a filename as its aria-label, which is not descriptive.
<div id="weather-filename-label-fail" role="img" aria-label="weather_icon_01.png" class="weather-container">
<div class="weather-icon">...</div>
<div class="temperature">70°F</div>
<div class="condition">Partly Cloudy</div>
</div>