Back to HTML Notes
Topic #124

Image alt Attribute

Learn how to write effective `alt` attributes for images to improve accessibility for screen reader users and enhance search engine optimization.

What it is

The alt attribute (alternative text) provides a text description of an image. It serves two primary purposes: it allows screen readers to describe visual content to users with visual impairments, and it helps search engines understand the context of the image. Think of alt text as a caption that describes what is happening in the image, not just what the file is named.

Why it matters

  • Accessibility: Screen readers cannot "see" images; they rely on alt text to convey meaning to blind or low-vision users.
  • SEO: Search engines use alt text to index images correctly, potentially driving traffic through image searches.
  • Context Preservation: If an image fails to load due to network issues, the alt text appears in its place, ensuring the user still understands the content.
  • Compliance: Proper alt text is required by web accessibility standards like WCAG (Web Content Accessibility Guidelines).

Syntax or steps

Add the alt attribute directly inside the opening <img> tag. The value must be a string enclosed in quotes.

  1. Identify the purpose of the image (informative, decorative, or functional).
  2. If informative, write a concise description of the content or function.
  3. If decorative, use an empty string (alt="") so screen readers skip it.
  4. Avoid starting with "Image of..." or "Picture of..." as screen readers announce this automatically.

Example

<!-- Informative Image -->
<img src="chart-sales-q3.png" alt="Bar chart showing sales increased by 15% in Q3 compared to Q2">

<!-- Decorative Image -->
<img src="divider-line.png" alt="" role="presentation">

<!-- Functional Image (Link) -->
<a href="/contact">
  <img src="email-icon.png" alt="Contact us via email">
</a>

In the first example, the alt text explains the data trend rather than just naming the file. In the second, the empty alt text tells assistive technology to ignore the decorative divider. In the third, the alt text describes the action the link performs.

Common mistakes

  • Redundancy: Writing "Image of a dog" instead of just "Dog." Screen readers already announce that it is an image.
  • Keyword Stuffing: Overloading alt text with SEO keywords makes it unreadable for humans and penalized by search engines.
  • Missing Alt Text: Omitting the attribute entirely causes some browsers to display the filename, which is confusing and unhelpful.
  • Describing the File Name: Using "photo_001.jpg" as alt text provides no semantic value.

When to use it

Every image requires an alt attribute. The decision lies in whether the content should be descriptive or empty.

Image TypeAlt Text StrategyExample
InformativeDescribe the content/functionalt="Sunset over the ocean"
DecorativeEmpty stringalt=""
Complex DataBrief summary + longdesc or nearby textalt="Sales graph (see table below)"

Practice

Guided Exercise: Write alt text for an image of a red bicycle leaning against a brick wall. Hint: Focus on the subject and setting without saying "image of."

Challenge: How would you handle an image that contains critical text information, such as a menu? Solution Hint: Do not rely solely on alt text for large amounts of text. Provide the text in HTML format near the image or use a detailed description.

Quick check

Question: Should you include the word "image" in your alt text?

Answer: No. Screen readers automatically announce that an element is an image, so adding "image of" creates redundancy.

Summary

Effective alt text balances brevity with clarity, ensuring that both human users with disabilities and search engine algorithms understand the visual content. Always ask: "If I couldn't see this image, what information would I need to know?"

Want to go beyond the notes?

Join Coding Now Tech Institute's HTML course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

Image alt Attribute – FAQs

Quick answers about learning Image alt Attribute in HTML.

This free note from Coding Now Tech Institute explains Image alt Attribute in HTML — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every HTML topic on Coding Now Tech Institute, including Image alt Attribute, is 100% free with no signup required.
With focused practice, most students grasp Image alt Attribute in 1–3 days from these notes; pairing it with Coding Now Tech Institute's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the Coding Now Tech Institute Community (/community) — expert instructors answer within 24 hours.
Call NowEnroll Now