When you add an image to a page in a content management system (CMS), you've probably seen a box for "alt text" or "alternative text". Most people write really poor alt texts for their images. But it doesn't have to be that hard.

What is alt text?

Technically, the alt text is a small attribute added to the HTML code for an image. It looks like this:

<img src="http://example.com/my-image.jpg" alt="" />

Not everyone can see images. But the image is often important. Without seeing it, the text is worth less. The alt text is there to explain what's in the image.

So the text is shown in place of an image. When the image can't be shown, for whatever reason, the visitor sees the alternative text instead. Hence the name.

Three uses for alt text

Alternative texts for images are needed and used for three main reasons:

  1. People with impaired vision, and others who use screen readers, need to be able to understand the image. They need the alt text to describe an image they otherwise can't see.

  2. Alt texts are shown if the image doesn't load for some reason. It might be a poor connection, or something else. The page still makes sense.

  3. Search engines can't see images either. They use alt texts to understand the images on the page, which helps them index the image and your page better.

Examples of different alt texts

Get a friend to help. Ask her to pick out an image. Close your eyes and let her describe it. If you can picture a reasonable version of the image from the description, it's a good one.

That's exactly how it works when you write alternative texts. You should be able to understand what matters in the image without seeing it.

Here are a few examples of alt texts for an image of a cup of hot chocolate.

A cup of hot chocolate topped with whipped cream and marshmallows
A cup of hot chocolate topped with whipped cream and marshmallows.

Okay: <img src="hot-chocolate.jpg" alt="Hot Chocolate" />

This alt text is only "okay". It isn't very descriptive. Sure, there's hot chocolate in the image, but there's more to say.

Good: <img src="hot-chocolate.jpg" alt="A cup of hot chocolate topped with whipped cream and marshmallows" />

This alt text is much better. It describes what's in the image in just enough detail and captures what matters.

Bad: <img src="hot-chocolate.jpg" alt="Come and visit our café for a cup of hot chocolate with whipped cream and marshmallows. Coffee break, café, chocolate. In the city centre." />

Here we've stuffed far too much into the alt text, in the belief that it helps search engines and your website's ranking. This is exactly what you shouldn't do. It won't give you the effect you're hoping for, and it's really bad for accessibility.

If the image has no purpose, it needs no alt text

Sometimes images have no purpose. They can be there purely as decoration. Then you don't need to write any alt text at all. Someone who can't see the image misses nothing but a bit of styling, so it makes no difference. In fact, an alt text would only confuse.

Alt text for search engine optimisation

For search engine optimisation, alt texts can matter too. Even though your main focus should be on accessibility, it's important to remember that Google also sees and reads your alt texts.

So remember to include the page's keyword in the alt text where it fits. The text should still feel right to someone who can't see the image. In the body text, you use your keyword now and then to make the page's topic clear. You can do the same in your alt texts.

Just don't overdo it, like in the bad example above.

How to write a good alt text: 5 rules

  1. Describe the image carefully and specifically.

  2. Keep the text fairly short. Aim for 125 characters at most.

  3. Use the page's keywords in the alt text too. It creates context for both visitors and search engines.

  4. Focus first and foremost on the people who can't see the image.

  5. Never write "image of" in your alt text. Everyone knows it's an alternative text in place of an image. You don't need to say so.