Alternative text gives an image a text equivalent when the image cannot be seen or loaded. Describe what matters for the page, not every color or pixel. Think about what the picture adds to the story, not just whether it looks nice on the screen.
What You Need to Know
If an image is only decoration, empty alt="" keeps it from being repeated by assistive technologies. When an image is a link, the alt text may need to name its destination.
Example: See It in Action
Try this markup in a fresh practice file. The next section explains the parts worth paying attention to.
This is a short HTML fragment. To try it as a webpage, put it inside the body element of a complete HTML document.
<main>
<h1>School Photos</h1>
<img src="images/classroom.jpg" alt="Students working together on laptops">
<img src="images/swoosh.svg" alt="">
</main>
Let’s Understand the Example
- Img displays an image. Src chooses the file and alt provides a useful text alternative.
- Main identifies the central content of the page; it should not be duplicated as separate visible main landmarks.
- Alt supplies a text alternative for an image. Empty alt is appropriate for purely decorative images.
- Src tells the browser where to find an image or other embedded resource.
An image appears only if its file path is correct. If it is informative, its alt text should share the same useful meaning; if it is decoration, empty alt text is often right.
What Should You See?
If the image file is available, the picture appears in the page. If not, the browser may show a broken image or fallback text. The example alt text is “Students working together on laptops”. Check that the text alternative fits the picture’s purpose.
Cover the picture and read the surrounding text aloud. If essential information has disappeared, add a useful text alternative or nearby explanation.
Try It Yourself
- Write different alt text for an informative classroom photo and a decorative shape.
- Save your changes, open or refresh the page, and compare the result with the original example.
- Tell a friend what your change did. If you are not sure, undo it, refresh the page, and compare.
Common Beginner Mistakes
- Using alt="photo" on every image, or leaving a decorative image with a noisy file-name announcement.
- Never guess at an image description. Write alternative text that matches the picture and its purpose on this page.
Key Takeaways
- Alternative text gives an image a text equivalent when the image cannot be seen or loaded.
- Img displays an image. Src chooses the file and alt provides a useful text alternative.
- If an image is only decoration, empty alt="" keeps it from being repeated by assistive technologies. When an image is a link, the alt text may need to name its destination.