The HTML alt attribute
The HTML alt attribute provides a text alternative for an image, shown if it fails to load and read by screen readers. It is used on the <img>, <area> and <input type="image"> elements.
Overview
The alt attribute provides a text alternative for an <img> — the description a screen reader announces, the text shown if the image fails to load, and a signal search engines use to understand the image. It is the most important accessibility attribute on an image.
Write alt that conveys the image's purpose in context, not a literal description of every pixel. A product photo's alt should be the product name; a chart's alt should state its key takeaway; an icon that opens a menu should describe the action ("Open menu"). Keep it concise — a phrase or short sentence — and do not start with "image of" or "picture of", since screen readers already announce that it is an image.
For purely decorative images that add no information, use an empty alt="" — this explicitly tells assistive technology to skip them. That is different from omitting alt entirely: a missing alt can make a screen reader read out the file name, which is worse than nothing.
Syntax
<img src="cat.jpg" alt="A ginger cat asleep on a sofa">
Values
| Value |
|---|
A short, descriptive string. Use an empty value (alt="") for purely decorative images. |
Example
<img src="https://codeshack.io/web/img/icon.png" alt="CodeShack logo" width="48" height="48">
Best practices
- Give every <img> an
altthat conveys its purpose in the surrounding context. - Use empty
alt=""for purely decorative images so screen readers skip them. - Keep it concise and drop "image of" / "picture of" prefixes.
- For complex images (charts, diagrams), summarize the takeaway in
altand provide full detail nearby.
Accessibility
alt is essential for accessibility and SEO. Describe the image's meaning or function, not its appearance. Use alt="" (empty, but present) for decorative images so screen readers skip them, and never omit the attribute entirely.
Frequently asked questions
What is alt text for?
When should the alt attribute be empty?
alt="" so assistive technology skips them.