Audit image-alt
Ensure <img> elements have alternative text or a role of none or presentation
Impact:
WCAG-Konformität:
- AWCAG 1.1.1
Issue types:
failure, needs reviewImage 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 ofpresentation
but instead add theimg
element to the accessibility tree with a semantic role of eitherimg
orgraphic
. - 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 emptyalt
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 explicitrole="none"
orrole="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 ofgraphics-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 asimage
,generic
orSvgRoot
.
Bibliography
- Understanding Success Criterion 1.1.1: Non-text Content
- G94: Providing short text alternative for non-text content that serves the same purpose and presents the same information as the non-text content
- G95: Providing short text alternatives that provide a brief description of the non-text content
- H37: Using alt attributes on img elements
- ARIA6: Using aria-label to provide labels for objects
- ARIA10: Using aria-labelledby to provide a text alternative for non-text content
- H67: Using null alt text and no title attribute on img elements for images that AT should ignore
- F38: Failure of Success Criterion 1.1.1 due to not marking up decorative images in HTML in a way that allows assistive technology to ignore them
- F65: Failure of Success Criterion 1.1.1 due to omitting the alt attribute or text alternative on img elements, area elements, and input elements of type "image"
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