Course contentsShow
← Web Development
Lesson 1143 of 2,98220. Screen Readers and Assistive TechnologyFree lesson

Context-Dependent Alt Text

Tailoring alt text based on the image's context and surrounding content to avoid duplication.

Context-Dependent Alt Text

What you'll learn: How to write alt text that fits the image's purpose and avoids repeating information already present in surrounding content.

Why Context Matters

The same image can serve different purposes depending on where it appears on a page. Alt text should reflect what the image contributes to that specific context, not just what the image contains.

Think of it like describing a photo to a friend. If they just asked "What's in the picture?", you'd give different details than if they asked "Why did you show me this picture?"

Writing for Context

When writing alt text, consider:

  • What information does the surrounding text already provide? Don't duplicate it.
  • What role does this image play here? Is it evidence, illustration, decoration, or a link?
  • What would be lost if the image disappeared? Include only that.

Examples in Different Contexts

Product listing page:

<!-- Surrounding text already says "Blue Cotton T-Shirt" -->
<img src="tshirt.jpg" alt="Front view showing crew neck and chest pocket">

Editorial article about fashion trends:

<!-- Same image, different purpose -->
<img src="tshirt.jpg" alt="Example of minimalist wardrobe staples">

Gallery without captions:

<!-- No surrounding context, so be complete -->
<img src="tshirt.jpg" alt="Blue cotton t-shirt with crew neck and chest pocket">

Notice how the alt text changes based on what information the user already has and what the image needs to communicate in that specific location.

Avoiding Duplication

If a caption or adjacent heading already describes the image content, your alt text should complement it rather than repeat it. This prevents screen reader users from hearing the same information twice.

Key Takeaway: Alt text should adapt to the image's purpose and surrounding content—describe what's unique or essential in that context, not everything visible in the image.