How to write alt text for images: rules, examples and length for SEO

· Heart Photos

A white castle with pointed towers and an arched bridge beside a rushing turquoise river
A white castle with pointed towers and an arched bridge beside a rushing turquoise river · Made by AI

Good alt text says, in a few words, what the image shows that matters on this page, as you would say it to someone over the phone. Be specific ("Dalmatian puppy playing fetch", not "dog"), skip "image of", never stuff keywords, and do not repeat the sentence next to the image. If the image is a link or a button, describe where it goes or what it does. If it is pure decoration, keep the attribute but leave it empty: alt="".

What is alt text, and who reads it?

Alt text is the alt attribute of an <img> element: words that stand in for the image. Three kinds of reader use it:

  • People using screen readers, who hear the alt text in place of the image.
  • Anyone whose image fails to load. MDN notes that the alt text "is also displayed on the page if the image can't be loaded."
  • Search engines. Google Search Central (updated Mar 2, 2026) says "Google uses alt text along with computer vision algorithms and the contents of the page to understand the subject matter of the image."

It is also the accessibility baseline: WCAG 2.2's Success Criterion 1.1.1, at the lowest level (A), asks that all non-text content have "a text alternative that serves the equivalent purpose."

And it is still the most skipped one. The WebAIM Million 2026 report (Mar 30, 2026) found missing alt text on 53.1% of the top million home pages, the second most common error after low-contrast text; 16.2% of all home page images had none.

How do you write good alt text?

Ask what the image is doing on this page, then write that, briefly. The HTML standard suggests a test that works almost every time: think about how you would read the page to someone over the phone, without mentioning that there is an image there.

  1. Describe what matters here, not everything in the frame. WebAIM's alternative text guide says the alt "should typically" be accurate and succinct: "Typically, only a few words are necessary, though rarely a short sentence or two may be appropriate."
  2. Be specific. Google grades three versions of the same photo: alt="puppy" is "Better" than none, and alt="Dalmatian puppy playing fetch" is "Best".
  3. Leave out "image of" and "graphic of". WebAIM explains that screen readers already announce the image, so the phrase is redundant. Say "photograph" or "painting" only when the medium itself matters.
  4. Do not repeat the text beside it. The HTML standard says the alt "should not repeat information that is already provided in the prose next to the image."
  5. Do not use the alt for a caption or a credit. Per the same standard, alt is replacement text, not a supplement; a caption belongs in <figcaption>, and MDN says the title attribute "is not an acceptable substitute for the alt attribute."
  6. Use keywords only where they are true. Google asks for alt text that "uses keywords appropriately and is in context of the content of the page" and warns that keyword stuffing "results in a negative user experience and may cause your site to be seen as spam."

What does good alt text look like?

The image at the top of this post is a good test. Here is how its alt text changes with the page it sits on:

Alt text Verdict
(no alt attribute) Bad: some screen readers read out the file name instead (MDN)
castle Too vague: which castle, doing what?
Image of a castle "Image of" adds nothing
castle castle photo fairytale castle river castle wallpaper Keyword stuffing, which Google warns against
A white castle with pointed towers and an arched bridge beside a rushing turquoise river Good on this post, where the image is the subject of an example
"" (empty) Right on a page where the image only sets a mood and the text says it all

The same image can need different alt text on different pages. WebAIM's guide shows this with a photo of astronaut Ellen Ochoa: on a page about her career, it recommends alt="Astronaut Ellen Ochoa", and rejects both "Image of Ellen Ochoa, Astronaut" (redundant) and a line about her achievements that the image does not show.

When should alt text be empty?

When removing the image would not make the page any less useful. The W3C's alt decision tree (updated May 13, 2024) gives alt="" for an image that is "purely decorative or not intended for users", and for one whose information is already in the text next to it.

Empty is not the same as missing:

  • alt="" tells assistive technology to skip the image. MDN says it marks an image as "not a key part of the content."
  • No alt at all is an error. The W3C's guide to decorative images warns that "some screen readers will announce the file name of the image instead."

What alt text does an image link or a button need?

Its job, not its look. The HTML standard says that when a link or button contains nothing but images, "the alt attributes must contain text that together convey the purpose of the link or button." A magnifying glass icon that opens search gets alt="Search", not alt="Magnifying glass". A logo that links to the home page gets the site's name, or "Home". Google adds that alt text on a linked image is used "as anchor text," so it counts like the words of a link.

What about charts, infographics and images of text?

  • Text in an image: put the text itself in the alt, unless the same words are already on the page, in which case the decision tree says to leave the alt empty.
  • Charts and diagrams: a short alt that names the chart and its main point, with the full data in the page or a table nearby. The decision tree says to "include the information contained in the image elsewhere on the page."
  • Social cards: the Open Graph protocol has og:image:alt, "A description of what is in the image (not a caption)," and says a page with an og:image should give it.

Frequently asked questions

How long should alt text be?

As short as it can be while still saying what matters, usually a few words to one sentence. Neither the HTML standard nor WCAG nor Google sets a character limit. If an image needs a paragraph to explain, put that paragraph on the page and keep the alt short.

Does alt text help SEO?

Yes, for images. Google says it uses alt text with the page's content to understand what an image shows, which is how an image can appear in Google Images for the right searches. It also helps the page by making it accessible. It is not a place to fit extra keywords: Google calls that spam.

Should alt text and the file name be the same?

They can say similar things, but they do different jobs. Google says a file name gives "very light clues", and prefers my-new-black-kitten.jpg to IMG00023.JPG. The alt text is what people hear, so write it as a phrase, not as a file name.

Do CSS background images need alt text?

They cannot have it, which is why the W3C recommends CSS backgrounds for decoration. Google says it "doesn't index CSS images," so any image you want found in search should be an <img> with alt text.

Should I start alt text with "image of" or "photo of"?

No. Screen readers already say it is an image. Name the medium only when it is the point, as with "Oil painting of..." on a page about art, or "Screenshot of the settings page" in a how-to.

Can AI write my alt text?

It can draft it, and it is a fair start for a large library, but check each one. WebAIM's guide puts it well: "algorithms alone cannot understand what an image means within the context of the overall page." A model sees a maple leaf; only you know whether your page means Canada.

What Heart Photos does

Every photo in Heart Photos has an Alt text field in its panel, next to the credit and the license, with the hint "Text to show if you can't see the photo." You can also set it when you upload through the API (an alt field on POST /api/v1/assets) or change it later (PATCH /api/v1/assets/{id}).

On a public photo's page, Heart Photos uses that text where it counts: as the alt of the image in the page's HTML, as its og:image:alt for social cards, and as the caption in the page's structured data. If you leave it empty, the image's alt falls back to the photo's title rather than being left out.

To add alt text to your own images, Open Heart Photos, open a photo and fill in Alt text. For the rest of making images fast and findable, see what size should images be for a website, how to fix Improve image delivery in PageSpeed Insights and should you lazy load images.

More from the blog