Loading...

Images require a description to be considered valid HTML.

Images can contribute greatly to a website's design. But if, for whatever reason, an image cannot be viewed, a lot of information can be lost. That's why you need to include the alt attribute with all your <img/> tags.

The alt attribute is where you add a description of what is shown in the image. While you don't need to be overly detailed, a description should include enough information that a person can imagine what the picture looks like with reasonable accuracy. This information should be concise and text based.

illustration of one page anchored to another with a boat anchor and chain
<img src="" alt=""/>

In addition to a website experiencing errors while loading, an image link can also break if the image file is moved or deleted from your directory. Since glitches and mistakes happen, alt attribute text would be used in place of the image and displayed where the image should have been. This is a way for users to know what visual information is being conveyed, even in the absence of the image itself.

Example

Working Image Broken Image
roller coaster train zooming through a loop roller coaster train zooming through a loop
<img src="roller-coaster.jpg" 
alt="roller coaster train zooming through a loop"/>

An extra benefit of having a thoughtful and semantic (meaningful) alt-text description is accessibility. Even if your images are working just fine, users who have visual impairments won't be able to see them. Assistive technologies like screen readers read out the text on websites. If you have useful information in an images alt-text, a screen reader will read that to the user instead. That helps visually impaired users get more out of your website. As of now, screen readers can't view and interpret images, but who knows what the future will hold?

In keeping with best practices, it's important that all images have an alt-tag present, but not all images require a text description. If you are using an image that is purely decorative, you do not need to provide a text description. A decorative image provides no information and is merely there to provide visual interest, so it's best to leave the alt-text description blank in this case.

Lesson Content Banner

Think you got it?

Complete the activity below by answering each prompt question in the provided text box. Once complete, you'll have the opportunity to compare your answers with the sample answers.

Would images on a pet-adoption site need alt-text description? Why or why not?

What type of meaningful description would you write for the following image?
Young golden retriever dog playing tug-of-war with a rope toy.

When should you leave an alt tag blank?

Your Responses Sample Answers
Yes. The images used on a pet-adoption site are useful to the viewer and can contain valuable information. How a pet looks, what they are doing, and their environment can tell a viewer a lot about a pet's personality and demeanor.
Answers may vary:
Meaningful Description: “Young golden retriever dog playing tug-of-war with a rope toy.”
Useless Description: “dog”
If an image is decorative in nature and its removal doesn’t decrease the value of the page content.