Skip to main content
In tritt das BFSG in Kraft - Ist Deine Website schon fit?Jetzt Website prüfen
Dieser Inhalt ist derzeit nur auf Englisch verfügbar

Audit image-alt

Ensure <img> elements have alternative text or a role of none or presentation

Impact:

Critical

WCAG-Konformität:

  • A
    WCAG 1.1.1

Issue types:

failure, needs review

Image has non-empty accessible name

This rule checks that each image either has a non-empty accessible name or is marked up as decorative.

Applicability

This rule applies to HTML img elements and HTML elements that are a semantic img, except if the element is programmatically hidden.

Expectation

Each target element has an accessible name that is not empty (""), or has a semantic role of none or presentation.

Background

Assumptions

There are no assumptions.

Accessibility Support

  • There are several popular browsers that do not treat images with an empty alt attribute (alt="") as having a role of presentation but instead add the img element to the accessibility tree with a semantic role of either img or graphic.
  • Implementation of Presentational Roles Conflict Resolution varies from one browser or assistive technology to another. Depending on this, some semantic img elements can fail this rule with some technology but users of other technologies would not experience any accessibility issue.
  • Images can have their role set to presentation through an empty alt attribute. Presentational Roles Conflict Resolution does not specify what to do if such an image is focusable (it only specifies what to do in case of explicit role="none" or role="presentation"). Some browsers expose these images and some don't. Thus, this rule may fail for technologies that expose these without creating an accessibility issue for users of other technologies.
  • svg elements have an implicit role of graphics-document in svg-aam. There are popular browsers that do not follow svg-aam and instead expose SVG elements with a different semantic role, such as image, generic or SvgRoot.

Bibliography

Test Cases

Passed

Passed Example 1

This img element has an accessible name because of the alt attribute.

<img alt="W3C logo" src="/test-assets/shared/w3c-logo.png" />

Passed Example 2

This semantic img element has an accessible name because of the aria-label attribute.

<div
	role="img"
	aria-label="W3C logo"
	style="width:72px; height:48px; background-image: url(/test-assets/shared/w3c-logo.png)"
></div>

Passed Example 3

This semantic img element has an accessible name because of an aria-labelledby attribute and an element with matching id.

<div style="display: none" id="img-label">W3C logo</div>
<div
	role="img"
	aria-labelledby="img-label"
	style="width:72px; height:48px; background-image: url(/test-assets/shared/w3c-logo.png)"
></div>

Passed Example 4

This img element has an accessible name because of a title attribute.

<img title="W3C logo" src="/test-assets/shared/w3c-logo.png" />

Passed Example 5

This img element has an implicit role of presentation because of the empty alt attribute.

<img alt="" src="/test-assets/shared/background.png" />

Passed Example 6

This img element has an explicit role of presentation because of the value of the role attribute.

<img role="presentation" style="width:72px; height:48px; background-image: url(/test-assets/shared/background.png)" />

Passed Example 7

This img element has an explicit role of none because of the value of the role attribute.

<img role="none" src="/test-assets/shared/background.png" />

Passed Example 8

This off screen img element has an implicit role of presentation because of the empty alt attribute.

<div style="margin-left:-9999px;">
	<img alt="" src="/test-assets/shared/background.png" />
</div>

Failed

Failed Example 1

This img element has an empty accessible name and an implicit role of img because it is missing an alt attribute.

<img src="/test-assets/shared/w3c-logo.png" />

Failed Example 2

This element with role of img has an empty accessible name.

<div role="img" style="width:72px; height:48px; background-image: url(/test-assets/shared/w3c-logo.png)"></div>

Failed Example 3

This img element inside a div positioned off screen has an empty accessible name and an implicit role of img.

<div style="margin-left:-9999px;"><img src="/test-assets/shared/w3c-logo.png" /></div>

Failed Example 4

This img element has an empty accessible name because the space in the alt attribute is trimmed off by the accessible name computation. Because of the space, the alt attribute is not empty ("") which gives the element the implicit role of img.

<img src="/test-assets/shared/w3c-logo.png" alt=" " />

Failed Example 5

This img element has an explicit role of none. However, it is focusable due to the tabindex attribute. Because of this it has a semantic role of img due to Presentational Roles Conflict Resolution. It does not have an accessible name.

<img role="none" tabindex="0" src="/test-assets/shared/w3c-logo.png" />

Inapplicable

Inapplicable Example 1

This semantic img element is hidden with aria-hidden set to "true".

<div
	role="img"
	aria-hidden="true"
	style="width:72px; height:48px; background-image: url(/test-assets/shared/w3c-logo.png)"
></div>

Inapplicable Example 2

This img element is hidden with aria-hidden set to "true".

<img src="/test-assets/shared/w3c-logo.png" aria-hidden="true" />

Inapplicable Example 3

This img element is hidden because its parent has display: none.

<div style="display: none">
	<img src="/test-assets/shared/w3c-logo.png" />
</div>

Inapplicable Example 4

This img element is hidden with visibility: hidden.

<div style="visibility: hidden">
	<img src="/test-assets/shared/w3c-logo.png" />
</div>

Autoren: Wilco Fiers

Vorherige Autoren: Anne Thyme Nørregaard, Stein Erik Skotkjerra

Finanzierung: WAI-Tools