When is it acceptable to leave the alt text empty on an HTML image (if ever)?
Asked Answered
C

1

34

It has been my understanding up to this point that the alt attribute is required, and should not be left blank. This seems to be confirmed in existing questions, such as this one.

However, in reading the HTML spec today, I noticed the following:

A single image can have different appropriate alternative text depending on the context.

In each of the following cases, the same image is used, yet the alt text is different each time. The image is the coat of arms of the Carouge municipality in the canton Geneva in Switzerland.

Here it is used as a supplementary icon:

<p>I lived in <img src="carouge.svg" alt=""> Carouge.</p>

It goes on to show other examples with various alt text, but this in this (and a couple other examples) the alt text is missing.

The spec later says (emphasis mine):

Except where otherwise specified, the alt attribute must be specified and its value must not be empty; the value must be an appropriate replacement for the image.

Is it ok to use alt=""? If so, when is this an acceptable use? If the image does not need alt text, should it be a CSS background image?

Note: This is based on the WHATWG HTML Living Standard, not the W3C HTML5 specification.

Countryside answered 7/5, 2014 at 19:37 Comment(2)
You are citing the so-called WHATWG Living HTML Standard, which is a mutable document and may and will change without notice; it does not call itself HTML5. It has some obscurities and vague formulations, and this one of them. Interpretations of such wordings are inevitably primarily opinion-based. Confusion is caused by not distinguishing lack of alt attribute from alt="". Constructive discussion of the issue would need to specify the expected uses of the alt attribute in browsers and assistive software.Calvert
I do understand the differences; I removed the 5 for clarity. As for this: "Confusion is caused by not distinguishing lack of alt attribute from alt="". Are you saying that I am causing confusion or that their specification is?Countryside
C
41

When to leave the alt attribute empty

Typically, the alt attribute is required; however, there are several cases in which the HTML spec says it is OK to leave the alt attribute's contents empty. The alt attribute is the text equivalent of the image, which means that it should only be empty if the meaning of the image is already encapsulated by the surrounding text.

Graphical representation of surrounding text (link)

It is important to think about the alt text as what content the image should be conveying in the case that it is unavailable. If the image can be summarized by text surrounding it, then it should have an empty alt attribute, because the redundancy would not be beneficial.

Examples include flowcharts or graphs that repeat the surrounding text.

If a caption is to be used, that caption should be included as a title element or using <figcaption>. The alt should be used if the graph can be described by information not available elsewhere on the page. The spec says the following on why this repetition should be avoided:

Including the caption in the alternative text like this isn't useful because it effectively duplicates the caption for users who don't have images, taunting them twice yet not helping them any more than if they had only read or heard the caption once.

Decorative images (link)

Generally, the spec recommends that the CSS background-image be used for this, but clarifies that in certain cases this may be done through the markup, such as a painting next to a poem, or a photo of the landscape at an event. In these cases, the images are content, but that content is only relevant if the user is able to see the images.

Groups of images that form a larger picture (link)

With no links

Only one image should have alt text to avoid repetitive text to users who can't see the images.

With links

The spec recommends that an image map be used for this instead, but if the image is sliced, there must be one image with alt text per link.

When to omit the alt attribute entirely

In some cases, the alternate text cannot be known or is unnecessary, and in these cases, alt="" is inaccurate, because it implies that the image does not add anything. The HTML spec warns:

If there is even the slightest possibility of the author having the ability to provide real alternative text, then it would not be acceptable to omit the alt attribute.

However, it acknowledges a couple of cases in which the alt may be omitted.

Unknown alt (link)

In certain cases, such as a blind user's blog or a photo sharing website where the metadata does not contain helpful information, the alt may be unknown.

In these cases, using the title attribute or a <figcaption> is required. Though it may be unknown the exact details of the image, some explanatory text should still be included. In this case, <figcaption> is preferred because

Relying on the title attribute is currently discouraged as many user agents do not expose the attribute in an accessible manner as required by this specification.

Known recipient(s) who can view images (link)

If you are writing a document that will only be viewed by a few known recipients, all of whom are known to be able to see images, the alt attribute may be omitted. It is recommended that the alt be included anyway, in case the email or document is forwarded.

Appendix: What about CSS background images?

If the image is not content, it should probably be a background image. For a breakdown of the rationale behind <img> vs. background-image, check out When to use IMG vs. CSS background-image?

Countryside answered 7/5, 2014 at 19:37 Comment(1)
This answer is useful, but imperfect. Firstly and most importantly, it would be hugely enhanced by facts about what today's real world visual browsers and screen readers do with alt, title and figcaption rather than what an idealistic document that's at least 4 years old has to say. Secondly, the advice about what to do when you know nothing about the image content (e.g. if you're an image hosting site, or you're Chrome generating an "Open image in new tab" document) is nonsensical; it amounts to "you MUST put the information you don't have somewhere other than the alt attribute". Huh?Hargrove

© 2022 - 2024 — McMap. All rights reserved.