Alt Text for Images

Alt Text for Images: Invisible Words That Matter

Every image on your website should tell a story — and that story should be accessible to everyone, including users who can’t see it. The alt attribute (short for “alternative text”) is how HTML makes that happen.

1. What Is alt Text?

Alt text is a string of text that describes an image. It appears in the HTML like this:

<img src="banana.jpg" alt="Ripe yellow banana on a wooden table">
[ Screen reader: "Ripe yellow banana on a wooden table" ]

When the image can't be displayed or is accessed by a screen reader, the alt text is what users hear or read instead.

2. Why alt Text Matters

  • Accessibility: Visually impaired users rely on screen readers.
  • SEO: Search engines index alt text to understand your images.
  • Fallback: When an image fails to load, alt text shows up.

3. How to Write Effective Alt Text

Do:

  • Be concise but descriptive.
  • Focus on meaning, not appearance.
  • Include relevant keywords naturally (for SEO, not spam).

❌ Avoid:

  • Redundant phrases like “image of…”
  • Keyword stuffing
  • Leaving it blank (unless it’s decorative)

Good Example

<img src="cherry-bowl.jpg" alt="Glass bowl filled with fresh cherries">

Poor Example

<img src="cherry-bowl.jpg" alt="cherry cherries cherry fruit red bowl cherry cherry">

4. Decorative Images

If an image is purely decorative — like a border or background flair — you should set the alt attribute to an empty string:

<img src="divider-line.png" alt="">
[ Screen readers skip the image completely ]

Why?

This avoids “visual noise” for screen reader users who don’t need descriptions of aesthetic-only visuals.

5. Alt Text and SEO

Search engines can't "see" images. They rely on alt text to interpret image content. This makes alt attributes especially useful for:

  • Product photos (e.g., “Red apple iPhone case with matte finish”)
  • Blog content imagery (e.g., “Chart showing banana export trends in 2023”)
  • Infographics and diagrams

Tip:

Make your alt text descriptive, accurate, and useful for users — and SEO will follow.

6. Alt Text in Practice: Examples

<img src="apple.jpg" alt="A single green apple with a bite taken out of it">

<img src="banana-smoothie.jpg" alt="Banana smoothie in a mason jar with a paper straw">

<img src="fruit-banner.jpg" alt=""> <!-- purely decorative banner -->

Summary

Alt text may seem small, but it has big impact. Here’s what we covered:

  • How to write effective and meaningful alt text
  • How alt text helps with accessibility and SEO
  • When to use empty alt text for decorative images
  • Best practices to avoid overdoing or misusing alt attributes

Check your understanding 1

Why is the alt attribute important for images in HTML?
Choose one answer. You can try again.

Answer and explanation

It improves accessibility by providing descriptions for screen readers

The alt attribute provides descriptive text that screen readers use to convey image information to visually impaired users, enhancing accessibility.

Check your understanding 2

Decorative images should always have meaningful alt text describing the image content.
Choose one answer. You can try again.

Answer and explanation

False

Decorative images should have an empty alt attribute (alt="") so screen readers can skip them, avoiding unnecessary distraction.

Check your understanding 3

Choose the option that lists all and only the correct statements.

  1. Be concise and descriptive
  2. Include important keywords for SEO
  3. Describe the image function or purpose
  4. Use long paragraphs explaining the image
Which of the following are good practices when writing alt text?
Choose one answer. You can try again.

Answer and explanation

Statements 1 and 2 and 3

Effective alt text is concise, describes the image’s purpose or content, and can improve SEO by including relevant keywords. Long paragraphs are discouraged as alt text should be brief.

Check your understanding 4

How can proper use of alt text impact SEO?
Choose one answer. You can try again.

Answer and explanation

It helps search engines understand the content of images, improving page ranking

Search engines use alt text to interpret image content, which contributes to better indexing and potentially improves search rankings.

Check your understanding 5

If an image contains important information, the alt text should convey that information accurately.
Choose one answer. You can try again.

Answer and explanation

True

Alt text for informative images should provide the same essential information the image conveys, ensuring accessibility and usability.

Check your understanding 6

Choose the option that lists all and only the correct statements.

  1. For purely decorative images
  2. For images containing vital content
  3. For images that link to other pages
  4. For background images set via CSS
When should you use an empty alt attribute (alt="")?
Choose one answer. You can try again.

Answer and explanation

Statements 1 and 4

Empty alt attributes are used for decorative images and background images so screen readers ignore them, reducing unnecessary noise for users.

What’s Next?

In the next tutorial, we’ll explore ARIA attributes and screen reader-friendly structure for complex components like modals, tabs, and custom buttons.

Reaching the recap and completing the quizzes are separate milestones.

    Next lesson: ARIA Roles in HTML →