Alt text helps describe images for people who cannot see them. It also helps search engines understand the image.
Alt text for images in HTML
<img src="image.jpg" alt="Description of the image">
The alt attribute must be inside the <img> tag.
Keep alt text short but descriptive, like a sentence or phrase.
<img src="cat.jpg" alt="A cute orange cat sitting on a windowsill">
<img src="logo.png" alt="Company logo">
<img src="decorative.png" alt="">
This page shows a heading, an image with alt text describing the dog, and a paragraph. If the image does not load, the alt text will appear instead.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Alt Text Example</title> </head> <body> <h1>My Favorite Animal</h1> <img src="https://example.com/dog.jpg" alt="A happy golden retriever dog playing in the park"> <p>This image shows a happy dog enjoying the outdoors.</p> </body> </html>
Always add alt text to every image for better accessibility.
If the image is purely decorative, use an empty alt attribute (alt="") so screen readers skip it.
Use clear and simple language in alt text to help all users understand the image.
Alt text describes images for people who cannot see them.
It improves accessibility and helps search engines.
Always include meaningful alt text or use empty alt for decorative images.
Practice
alt attribute in an <img> tag?Solution
Step 1: Understand the role of alt text
Thealtattribute gives a text description of the image content.Step 2: Recognize accessibility and fallback use
This text helps screen readers for visually impaired users and shows if the image fails to load.Final Answer:
To provide a text description of the image for screen readers and when the image cannot load -> Option BQuick Check:
Alt text = image description [OK]
- Thinking alt changes image size
- Using alt to add styling like borders
- Confusing alt with links
Solution
Step 1: Identify the correct attribute for alt text
The correct attribute to describe images isalt.Step 2: Check the syntax of the
<img>tag<img src="flower.jpg" alt="Beautiful red flower">usesalt="Beautiful red flower", which is correct HTML syntax.Final Answer:
<img src="flower.jpg" alt="Beautiful red flower"> -> Option AQuick Check:
Use alt attribute for image description [OK]
- Using non-existent attributes like description or text
- Confusing alt with title attribute
- Omitting quotes around alt text
<img src="logo.png" alt="Company logo">
Solution
Step 1: Understand screen reader behavior with alt text
Screen readers read thealtattribute to describe images to users.Step 2: Check the alt attribute content
The alt text is "Company logo", so the screen reader will announce this phrase.Final Answer:
It will say 'Company logo' aloud -> Option AQuick Check:
Screen reader reads alt text [OK]
- Assuming screen readers read image file names
- Thinking screen readers ignore images with alt
- Confusing alt with title attribute
<img src="photo.jpg" alt>
Solution
Step 1: Check the alt attribute syntax
The alt attribute must have a value, likealt="description". Here it is empty without ="...".Step 2: Confirm other attributes and tag correctness
The src attribute is correct, and<img>is self-closing in HTML5, so no closing tag needed.Final Answer:
The alt attribute is missing a value -> Option DQuick Check:
Alt attribute needs a value in quotes [OK]
- Leaving alt attribute empty without =""
- Thinking img needs a closing tag
- Using invalid attribute names like alt-text
img tag for best accessibility?Solution
Step 1: Understand alt text for decorative images
Decorative images should have empty alt text (alt="") so screen readers skip them.Step 2: Evaluate options for accessibility
<img src="decorative.png" alt="">uses empty alt, which is correct. Omitting alt or using generic text causes confusion.Final Answer:
<img src="decorative.png" alt=""> -> Option CQuick Check:
Empty alt hides decorative images from screen readers [OK]
- Omitting alt attribute entirely
- Using vague alt text like 'image' or 'decorative image'
- Adding unnecessary descriptions for decoration
Ready to prove it?
Pass the test and this pattern moves unknown
