HTML alt Attribute

Beginner
6 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The alt attribute defines text that can replace an image when the picture is not available — for screen readers, users who turn images off, or when the file fails to load.

On <img>, pair it with src. Also used on <area> (image maps) and <input type="image">. Write a concise replacement for the image’s meaning — not the word “image” or the file name.

Baseline · Widely available.

Not deprecated. Essential for accessibility. Stable across modern browsers since about July 2015.

Do not omit it.

Missing alt may make screen readers announce the file name. For decoration, use an explicit empty value: alt="".

HTML Syntax

syntax.html
<img src="…" alt=" text">

Use alt="" when the image is decorative and should be ignored by assistive technology.

Attribute Values

How to choose the alt string:

ValueDescriptionTry it
Meaningful textClear, concise replacement for the image contentTry it
alt=""Decorative / redundant with nearby text — skip for screen readersTry it
Action textFor linked or button images, describe the action (e.g. Next page)Try it
AvoidDo not use alt="image", the file name, or omit the attributeTry it

Live Preview

Change the alt text. Force a broken image to see how the browser shows the alternative.

Toggle “Show broken src” to see how alt appears when the image cannot load.

Image

CodeToFun logo

alt="CodeToFun logo"

HTML Examples

Short, copy-ready snippets. Use Try It Yourself for a live editor.

Example 1 — Meaningful Alternative Text

Describe the content, not the fact that it is an image.

HTML
<!-- Don't -->
<img src="penguin.jpg" alt="image">

<!-- Do -->
<img src="penguin.jpg" alt="A penguin on a beach.">
Try It Yourself

How It Works

  1. alt replaces the picture when it cannot be seen or loaded.
  2. Be specific — “A penguin on a beach” beats “image”.
  3. Keep it short — enough to carry the same meaning in context.
  4. Read it with nearby text — the sentence should still make sense.

Example 2 — Decorative Image with Empty alt

When the image adds no new information, use alt="".

HTML
<h3>
  <img src="article-icon.png" alt="" width="24" height="24">
  Tyrannosaurus Rex: the king of the dinosaurs
</h3>
Try It Yourself

How It Works

  1. Empty string is intentional — alt="", not a missing attribute.
  2. Assistive tech skips the decorative graphic.
  3. Heading text already names the topic.
  4. CSS backgrounds are another option for pure decoration.

Example 3 — Image Inside a Link

Describe the action or destination, not just the picture.

HTML
<a href="https://developer.mozilla.org/">
  <img
    src="/images/codetofun-logo.png"
    width="96"
    height="96"
    alt="Visit MDN">
</a>
Try It Yourself

How It Works

  1. The image is the link — alt becomes the accessible name.
  2. Prefer the action (“Visit MDN”) over “logo” or “arrow”.
  3. If text is beside the image in the same link, often use alt="" to avoid duplication.
  4. Do not rely on title instead of alt.

Edge Cases & Pitfalls

Most alt mistakes are “too vague,” “missing,” or “duplicated.”

omit

Missing alt ≠ empty alt

Leave the attribute off and some screen readers speak the file name. Use alt="" for decoration.

title

title is not a backup

Do not put the same string in title and alt. For captions, use <figure> and <figcaption>.

keywords

Avoid keyword stuffing

Alt is for people first. Stuffing SEO phrases hurts clarity and trust.

maps

<area> needs useful labels

Linked regions in an image map should have non-empty alt that describes the choice.

context

Same file, different alt

Alt depends on context. A chart may need a summary; a logo in a nav may say the site name.

Browser Support

alt is an HTML attribute for images (and related elements) in the browser. It is not a Node.js, Deno, or Bun API.

✓ Baseline · Widely available

alt

Supported everywhere images are. Assistive technologies rely on it; visual browsers show it when the image cannot load.

100% Attribute support
Google Chrome All modern
Full support
Mozilla Firefox All modern
Full support
Apple Safari All modern
Full support
Microsoft Edge All modern
Full support
Opera All modern
Full support
Samsung Internet All modern
Full support
Internet Explorer All versions with images
Supported
alt Widely supported

Bottom line: Always provide alt. Use meaningful text for content images and alt="" for pure decoration.

Key Takeaways

  • Role: text replacement for the image’s meaning.
  • Empty: alt="" for decoration — do not omit the attribute.
  • Quality: describe content or action — not “image” or the file name.
  • Not title: title is not a substitute for alt.

One line: every <img> needs alt — meaningful text, or alt="" if it is only decoration.

Frequently Asked Questions

It provides text that can replace an image when the image is not shown — for screen readers, blocked images, or load errors. On img it is a textual replacement for the picture.
Primarily img. It is also used on area (image maps) and input type="image" (submit buttons that are images).
Use alt="" for purely decorative images (or when nearby text already says the same thing). That tells assistive tech to skip the image.
No. Missing alt may cause screen readers to announce the file name. Prefer an explicit empty alt for decoration.
No. title is not a substitute. Do not duplicate the same string in both — some screen readers may read it twice.
No. It is required for accessible images and is Baseline widely available.

Next: archive

Legacy attribute for object archives — rarely used today.

archive tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful