In a project I worked on recently, I noticed almost everything in the page had alternative text. Sometimes this can be redundant, for example if there is already text on the page that says what the thing is. Let’s look at some examples.
Why alternative text
A lot of the web is text. This is great. As a medium, that makes the web super parseable for external tools like search engines and assistive technologies (AT). It makes it even a better medium than the real world, where such parsing still requires a lot more effort. Until machine learning is ubiquitous, I guess, the fact that we have so much text on the web, makes the web the ultimate medium for accessible content.
When it is needed
Whenever we include non-text elements on a page, it is a good practice to add alternative text. For example, when adding an image, whether it is a photo or something with three words of text in it, we can use the
alt attribute to convey what’s on the image to anyone who can’t see it. We’ve all seen this:
<img src="delirium.jpg" alt="A pink elephant" />
Or when adding a video, it is useful to add subtitles, for users who cannot hear the people talking in the video:
<video src="instruction-video.mp4"> <track src="instruction-video.vtt" /> </video>
When it is not needed
Sometimes, alternative text is redundant. Look at these examples:
Speaker photos on a conference website
A page is divided in sections, with sections for each speaker. The heading in the section is the name of the speaker. There is also a portrait of the speaker. The photo does not require alternative text here, as it would be the same as the section heading, and that would be redundant. Note that the
alt attribute is required, so in this case I would recommend an empty alt attribute:
Here’s a close button:
<button type="button"> <img src="close.svg" alt="Close" /> </button>
In this case, there is only an icon, it exists on its own. An alternative text would be useful here, especially since it is used as an interactive element (like
<button> ). If a button is just an icon, it does not have text that can function as the element’s ‘name’. So when, for example, a screenreader announces ‘button’, it doesn’t announce what the button is (as it doesn’t know). Adding a text like ‘Close’ helps with that, so that the screenreader can announce ‘button - close’
But when an icon has a word next to it, for example ‘Log out’, the icon itself is decorative and does not need an alternative text:
<button type="button"> <img src="close.svg" alt="" /> Close </button>
In this case we can leave the
alt attribute empty, as otherwise a screenreader would announce ‘button - close close’.
When captions describe photos
Sometimes, photos come with visible captions that describe them. In these cases, it is not necessary to add text into the
alt of the photo, as the alternative text is already out there, the description has fulfilled the need.
Alternative text is a great opportunity to make the non-text parts of the web accessible. However, look out for redundancy, and only add it when it conveys something that isn’t already there.