When the alt
attribute is set to the empty string
From the W3C:
The image is either decorative or supplemental to the rest of the content, redundant with some other information in the document.
The second part about redundancy is important, for instance:
<h1><img alt="" src="logo.gif" />My company name</h1>
When you have to use the role=presentation
This is the case when the image is purely decorative which means that you must use alt=""
in this case.
You should not have to specify the presentation role attribute for an image with an empty alt
attribute as it's the default implementation of the standard browsers:
Allowed ARIA role attribute values:
presentation
role only, for an img
element whose alt
attribute's value is empty (alt=""
), otherwise Any role value.
When you have to use aria-hidden=true
Use it when you do not want to provide an information to the Accessibility API, but want to give it to standard users.
As sighted people may use a screenreader (illiterate, low-vision, ...) it's must be used with caution. For an img
tag, it's only useful when the alt
is not empty.
For img
with a non empty alt
attribute, it will assume that you provide sufficient contextual information for people using screenreaders, and the alt
information may only provide information already visible on the image and not interesting blind people or other screenreader users.
<h1>Come to visit George</h1>
<img alt="Map to reach George" src="map.gif" aria-hidden="true" />
Take the highway A13 direction London.
When you reach London follow A2 highway in direction Liverpool.
I think this is more useful for SEO without introducing redundancy.
TL;DR
When you do not want to provide information to screen readers:
- If SEO is a concern, use a non empty
alt
with aria-hidden=true
- Otherwise use
alt=""
img
with role=presentation
should have an empty alt
img
with an empty alt
have implicit role=presentation