DEV Community

Dhamith Kumara
Dhamith Kumara Subscriber

Posted on

Why the alt Attribute Matters?

Images are an essential part of the web. They inform, engage, and enhance the overall user experience. But what happens when an image fails to load, or when a user cannot see it? That’s where the humble alt attribute of the <img> tag comes into play, serving as a vital link between visual content and universal accessibility.

What is the alt Attribute?

The alt attribute in HTML provides alternative text for an image. This text is displayed if the image cannot load. More importantly, it is read aloud by screen readers, helping visually impaired users understand the content and context of images.

sample of correct alt tag

Why is the alt Attribute Important?

The alt attribute serves several important purposes,

1. Accessibility for Screen Readers

Visually impaired users rely on screen readers to navigate the web. The alt text provides a textual description of images, giving these users critical context and meaning that would otherwise be lost.

2. Context When Images Fail to Load

If a browser can’t load an image due to network issues, broken links, or other problems, the alt text appears in its place. This helps users understand what information they are missing and maintains the continuity of the page content.

3. Improved Search Engine Optimization (SEO)

Search engines can't "see" images the way humans do. The alt attribute provides important context about the image, helping search engines understand your page content better. Well written alt text can improve image search rankings and overall SEO performance.

4. Support for Text Based Browsers

Though increasingly rare, some users still use text based browsers. The alt text ensures these users access the information conveyed by images.

Crafting Effective alt Text

Writing good alt text is an art that balances clarity, brevity, and context. Follow these principles to write meaningful alt attributes,

  • Be Descriptive and Contextual - Describe the image and its purpose as if explaining it to someone who can't see it.

  • Keep it Concise - Aim for a brief, one or two sentence description. Overly long alt text can burden screen reader users.

  • Use Relevant Keywords Naturally - If relevant, include keywords thoughtfully to benefit SEO, but avoid keyword stuffing.

  • Avoid Redundant Phrases: Don’t use phrases like "image of" or "picture of" screen readers already announce images.

  • Reflect the Image's Function - If the image functions as a link or button, describe its purpose or destination.

  • Use Empty Alt for Decorative Images - For purely decorative images that add no content value, use an empty alt attribute alt="" to allow screen readers to skip them.

  • Use Real Text Instead of Text in Images - Whenever possible, avoid using images to display text. Use HTML text for better accessibility and SEO.

Good and Bad Examples

alt first good example

Good ✔

Why?

  • It's descriptive and specific.
  • It tells both what the image is (company logo) and what it depicts (a stylized blue bird in flight).
  • Helpful for screen readers and gives useful context.

alt second good example

Good ✔

Why?

  • It’s clear, descriptive, and paints a specific image in the reader’s mind.
  • Great for accessibility and good for SEO because it naturally mentions relevant, specific content without overdoing it.

alt first bad example

bad ❌

Why?

  • It’s too vague and doesn’t tell what the logo represents.
  • Screen readers users would just hear “logo”, which is unhelpful.

alt second bad example

bad ❌

Why?

  • This is a classic example of keyword stuffing.
  • It's a list of keywords with no real sentence structure or meaning.
  • Bad for accessibility (screen readers will read this awkwardly) and can harm SEO.

How Alt Text Fixer Can Help You

Managing alt attributes manually can be tedious, especially on larger projects. That’s why I created Alt Text Fixer, a lightweight and beginner friendly Visual Studio Code extension that helps you quickly find missing alt attributes and add or edit them directly in your editor.

Key Features -

  • Scan your files for images missing alt attributes
  • Quickly add or update alt text without leaving VS Code
  • Improve your site's accessibility and SEO compliance effortlessly
  • Lightweight and fast, perfect for developers of all skill levels

get it now

Top comments (0)