Hello World
Hello, welcome to Accessibility for Developers. This is a free site aimed at giving straight forward guides on how to make your websites and…
Read more, Hello WorldLast updated on May 01, 2015• A11y issues
Alt text is the alternative text given to images. It is probably one of the first accessibility related things that website developers learn about. Without adding alt text, assistive technologies such as screen reads would not be able to describe the image to users* and will just describe it as ‘an image’.
* sometimes screen readers will attempt to read the filename (such as DSC0001.jpg
), and AI tools are starting to appear that can try and describe images
It is sometimes known as the alt description or alternative text.
The markup in HTML is very simple - just adding text to the alt
property.
For example:
<img src="swan.jpg" alt="Swan in the water" />
swan.jpg
), but this is often not very useful.Writing good alt text is quite subjective. There are many views on how to write good alt text. The main consensus is:
Alt text is to give users who cannot see the image an understanding of the image, so they can understand the rest of the page.
A short alt text is normally enough to give enough information so people can understand the content. But don’t make it too short.
For example if you had a website on how to plant seeds, with an image showing how/where to put seeds. A bad alt text might be just planting carrot seeds
. A better alt text might be planting 6 carrot seeds 1cm deep, with 20cm between them
.
It should not include wording such as a picture of...
, an image of...
as screen readers will already describe it as an image. Just skip those first three words and go straight into what it is an image of.
(don’t include the weather, how sunny it is, how many people are in the background). The alt text is to describe the image, not to add additional information. These probably belong in a <caption>
tag near the image…
If you had an article about baseball bats, and you had a photo of a baseball bat you might want to describe the baseball bat. But you can probably (don’t include the weather, how sunny it is, how many people are in the background) (don’t include the weather, how sunny it is, how many people are in the background).
This does mean that the same image could probably have completely different alt texts depending on where it is used. This is why using a CMS that lets you upload an image and set alt text is probably causing some issues - it depends on where and how the image is used that determines how you should decide on an alt text!
If there is a very critical image - for example a diagram - then you should probably describe it just in text outside of the alt text. It is likely that for complicated images that users need to understand the alt text would have to be too long. Just stick it as a paragraph outside of the <img>
tag…
If you have icons that represent something, it is probably very important to include alt text for them.
But describe what information they’re trying to convey - an icon of Facebook’s logo should probably be described as Facebook logo
, and not White F on blue background
.
This is in my opinion almost as important as adding alt text… knowing when to not add alt text!
There are cases when you don’t want screen readers to read out the image. You might think that by just not including the alt
property it would mean screen readers will skip it. But they will often try and guess the image by reading the filename (DSC1101.jpg
). So to make screen readers skip reading an image out loud then just add alt=""
.
If you had an image between paragraphs (and let’s say you used <img>
for this - not in CSS) that had squiggly lines. Is that important for screen readers? Very unlikely! It is just decorative.
Some things like squiggly lines are quite easy to tell that they’re decorative. But what about an article with some stock photo in it? Is that decorative? Would the article make sense even if you couldn’t see the image? Then it is probably decorative.
If a button or link has normal text, but also an image then the alt text might not be needed. For example <a href="/shop"><img src="i.png" alt="Go to our shop" /> Go to our shop</a>
would mean screen readers read the same ‘go to our shop’ text twice. Just stick an empty alt text in there so screen readers will skip it - <a href="/shop"><img src="i.png" alt=""> Go to our shop</a>
A good tip when quickly deciding if you need to use an alt text is to imagine you were describing the page to someone on the phone.
Would you mention that there was a squiggly line (decoration image) between paragraphs? Probably not.
If you were on a page about a castle, would you describe that there was a picture of the castle, explaining what it looked like? Probably!
Don’t aim to fill it up, but try to avoid going over 125 characters. This is generally what is advised both for SEO and accessibility reasons.
Here are some more great resources on alt tags for accessibility:
Please consider sharing this link with your work colleagues or on social media. There are no ads on my site, I just want to promote accessibility.
Found an issue? please point them out - let me know if there is a mistake and I'll update it
Follow me on Twitter: @A11yForDevs. I post links to interesting a11y articles and resources.
Hello, welcome to Accessibility for Developers. This is a free site aimed at giving straight forward guides on how to make your websites and…
Read more, Hello World