Skip to content
Guides

Writing alt text for images: rules and examples

What is alt text, when do you leave it empty, and how do you describe a product photo, logo or chart? A practical guide with good and bad examples.

What is alt text?

Alt text (alternative text) is the text in an image's alt attribute. It replaces the image for anyone who cannot see it. In HTML it looks like this:

<img src="blue-raincoat-front.jpg" alt="Blue raincoat with hood and press studs, front view">

The visitor sees the photo; the alt text sits in the code. You will often hear "alt tag", but strictly speaking alt is an attribute of the <img> element. In most content management systems and shop platforms you fill it in on the image itself, in a field often called "Alternative text". See also alt text in the encyclopedia.

Who uses alt text?

Screen readers, browsers, search engines and any program that only reads the text of a page.

  • Blind and partially sighted visitors can use a screen reader that reads the page aloud. When it reaches an image, it reads the alt text. That is why the WCAG accessibility guidelines require a text alternative that serves the equivalent purpose for every image that conveys information.
  • Browsers show the alt text when the image fails to load, for example on a slow connection or with a wrong file path.
  • Google uses alt text together with computer vision and the content of the page to understand what an image is about (image guidelines). If the image is a link, Google uses the alt text as the link text (link best practices).
  • Programs that only read text, such as a crawler that does not look at the image itself, see only what is in the HTML at that spot: the file name and the alt text.

How do you write good alt text?

Describe briefly and concretely what the image shows and what matters for this page, as if you were explaining it to someone over the phone. In its SEO Starter Guide, Google describes alt text as a short but descriptive piece of text that explains the relationship between the image and your content. In Google's own example, "puppy" is better than nothing, but a Dalmatian puppy playing fetch is best: specific, without unnecessary words.

<!-- Wrong: no alt attribute and a meaningless file name -->
<img src="IMG00023.jpg">

<!-- Weak: too general -->
<img src="coat.jpg" alt="coat">

<!-- Wrong: a string of keywords -->
<img src="coat.jpg" alt="raincoat coat buy raincoat women raincoat men cheap raincoat waterproof coat">

<!-- Good: describes what can be seen -->
<img src="blue-raincoat-front.jpg" alt="Blue raincoat with hood and press studs, front view">

Rules of thumb:

  • Be specific. Name what someone would miss without the image: the product, the colour, the action, the place.
  • Think about context. The same photo may need different alt text on two pages. A photo of a cyclist on a riverside path might be "Cyclist on a grey gravel bike" on a bike shop's page, and "Riverside cycle path with a view across the water meadows" on a route page.
  • Keep it short. A sentence or a few words is usually enough. Detailed information belongs in the text itself.
  • Leave out "photo of". It rarely adds anything. In one of its logo examples, the W3C notes that there is no need to mention that it is a logo.
  • No keyword lists. Google calls that a poor user experience that may cause your site to be seen as spam.
  • Write in the language of the page. A screen reader reads the alt text in the language of the page, so alt text in another language sounds odd.

When do you leave the alt text empty?

When the image is purely decorative, or when the information is already in the text next to it. Then you write alt="". A screen reader then skips the image. Do not leave out the attribute altogether: without alt, some screen readers read out the file name instead, as both the W3C and MDN point out.

<!-- Decorative: a divider between two paragraphs -->
<img src="/img/divider.svg" alt="">

<!-- Redundant: the link text already says what the image shows -->
<a href="/raincoats/">
  <img src="raincoat-collection.jpg" alt="">
  Raincoats
</a>

Not sure whether an image is decorative? Ask yourself: would someone who cannot see the image miss part of the content? If so, it is not decorative. The W3C has a handy decision tree with questions such as: does the image contain text, is it inside a link or button, and does it add meaning?

The W3C recommends showing purely decorative images as CSS backgrounds where possible. Note, though, that Google does not index CSS images. An image that needs to be found or conveys information belongs in an <img> element.

Which alt text suits which type of image?

The type of image determines what belongs in the alt text: a description, the destination of a link, the text it contains, or nothing. The categories below follow the W3C decision tree.

Type of image Alt text
Product photo: raincoat in an online shop "Blue raincoat with hood and press studs, front view"
Photo in an article: balcony with vegetable planters "Balcony with wooden planters full of lettuce and cherry tomatoes"
Logo without a link: logo in a row of client logos "Example Bakery"
Logo as a link to the home page, top left in the header "Example Bakery home page"
Icon as a button: magnifying glass next to a search box "Search"
Image containing text: banner reading "Free delivery on two items or more" "Free delivery on two items or more"
Chart: bar chart of orders per month Short alt; the figures in the text or a table below
Decoration: divider or background pattern Empty: alt=""

Notes on the trickiest cases:

  • Logos. A logo without a link gets the company name; there is no need to say it is a logo. If the logo links to the home page, describe the destination. The W3C gives "Example.com homepage" rather than "Example.com logo" as an example.
  • Icons and buttons. Describe the action, not the picture: "Search" rather than "magnifying glass", "Next page" rather than "right arrow". MDN gives the same advice for images inside links.
  • Images containing text. Include the same text in the alt (W3C: Images of Text). Even better is real text styled with CSS: everyone can read that.
  • Charts. A chart contains too much information for a single alt text. The W3C recommends a two-part alternative: short alt text that says what the chart is, and a longer description on the page, for example in a caption or a table (W3C: Complex Images).
<figure>
  <img src="orders-per-month.png" alt="Bar chart: number of orders per month, detailed in the table below">
  <figcaption>Orders per month. The table below gives the numbers for each month.</figcaption>
</figure>

What else should you do besides alt text?

Give the image a descriptive file name, place it next to the text it belongs to and use a real <img> element. Those are the other tips in Google's image guidelines:

  • File name. blue-raincoat-front.jpg says more than IMG00023.jpg. Google recommends short, descriptive names and advises against generic names such as image1.jpg.
  • Placement. Where possible, put images near the text they relate to. Google also takes information about an image from the content of the page, such as captions.
  • Caption. A <figcaption> inside a <figure> is visible to everyone. Use it for information that helps sighted visitors too, and do not repeat it word for word in the alt.
  • <img> rather than CSS. Google finds images in the src attribute of <img>, including inside a <picture> element, but does not index CSS images.
  • No title instead of alt. The title attribute shows a tooltip when you hover over the image, but according to MDN it is no substitute for alt.

How do you check the alt text on your site?

List all the images on a page with their alt text and see which are missing or meaningless.

  1. Open the page in Chrome, Edge or Firefox, press F12 and go to the Console tab.
  2. Paste the code below and press Enter. Chrome may first ask you to type allow pasting. Only paste code you understand.
console.table([...document.images].map((img) => ({
  file: (img.currentSrc || img.src).split("/").pop(),
  alt: img.hasAttribute("alt") ? img.alt || "(empty)" : "MISSING",
})));
  1. Go through the list:
    • MISSING: add alt text, or alt="" if the image is decorative.
    • (empty): is this image really decorative or redundant?
    • A file name or a single word ("coat", "DSC_0042"): turn it into a description.
    • The same text on every image: often a default value from a theme or plugin.

To really experience it, try a screen reader. VoiceOver is built into macOS and iOS, and NVDA is a free screen reader for Windows. Have a page read aloud and listen whether you understand what the images show without looking.

Checklist

  • Every <img> has an alt attribute.
  • Informative images have a short, specific description.
  • Decorative or redundant images have alt="".
  • Images in links and buttons describe the destination or the action.
  • Text inside an image is also in the alt.
  • Charts have short alt text and an explanation on the page.
  • No keyword lists in alt text.
  • File names are descriptive.
  • Important images are in an <img>, not a CSS background.

Curious about the rest of your HTML? The free scan checks, among other things, the title, the meta description and the heading structure of your home page.

Frequently asked questions

Is alt text the same as an alt tag?

In practice, yes. Strictly speaking, alt is not a tag but an attribute of the img element. Alt tag, alt attribute and alternative text all mean the same thing.

How long can alt text be?

There is no fixed limit. Keep it short: a sentence or a few words is usually enough. If an image contains a lot of information, such as a chart, the W3C recommends short alt text plus a longer description on the page, for example in a caption or table.

Should my keyword be in the alt text?

Only if it genuinely describes the image. Google recommends descriptive alt text that fits the content of the page, and warns that stuffing alt attributes with keywords creates a poor user experience and may cause your site to be seen as spam.

Is the tooltip that appears when you hover over an image the same as the alt?

No. That tooltip usually comes from the title attribute. According to MDN, the title attribute is not an acceptable substitute for the alt attribute. So always fill in the alt; a title is optional.

What about images I show as a CSS background?

That is fine for decoration: the W3C actually recommends CSS backgrounds for purely decorative images. But Google does not index CSS images. If an image needs to be found or conveys information, use an img element with alt text.

Sources

  1. Google Search Central: Image SEO best practices
  2. Google Search Central: SEO Starter Guide
  3. Google Search Central: Link best practices for Google (images as links)
  4. MDN: <img>: The Image Embed element
  5. W3C WAI: An alt Decision Tree
  6. W3C WAI: Decorative Images
  7. W3C WAI: Functional Images
  8. W3C WAI: Images of Text
  9. W3C WAI: Complex Images
  10. W3C: Understanding WCAG 2.2 Success Criterion 1.1.1 Non-text Content

How visible is your website?

Find out for free how you score in Google and in ChatGPT, Gemini and Claude.

Start free scan

Read also