alt
Attribute in HTML5
I asked on Twitter and on Juicy Studio for opinions about whether or not the alt
attribute should be required in HTML 5 on the img
element for conformance and the reasons why. The following is a summary of the responses for and against requiring the alt
attribute.
alt
Attribute Should Be Requiredalt
attribute should be used or the content will not be perceivable to some users.alt
attribute should be mandatory in HTML5 with a note pointing to WCAG 2.0 for guidance, as WAI are the experts in this area.alt
attribute allows broad, dangerous ideas of what should and should not have alt. Laziness will dictate.alt
attribute should be required, or an additional attribute provided to indicate when alt text has not been provided.alt
Attribute Should Not Be Requiredalt
attribute required results in people providing nonsense values.alt
attribute required does not mean it will be used correctly.aria-labelledby
is better than requiring the alt
attribute.alt
attribute should not be required, but flagged at validation as a warning.
When alt text has not been provided by the author and it is not possible to generate meaningful meta data about the image, the authoring tool should not generate default alt text, as that is likely to result in poor quality alt text; the number one reason given by those who responded that alt text should not be required. When alt text has not been provided, and it is not possible for the authoring tool to generate any kind of repair, such as meta data, the alt
attribute should be omitted. The resulting output, however, should be considered invalid, as it is not structurally complete.
It is unreasonable to state that the output from authoring tools should always be considered valid, regardless of input from the user. Considering output to be correct regardless of input is at odds with the general garbage in garbage out (GIGO) principle. For example, an author can provide an address with the address
element that isn't a contact address, which would not be considered compliant. The author obviously has a responsibility in using an authoring tool.
A markup language should be concerned about structure. The img
element is not complete without an alternative, as it will not be perceivable by some people. The simplest and easiest way to ensure the img
element is structurally complete is to provide an alt
attribute in accordance with guidance provided by WCAG 2.0. If the alt
attribute is not provided, there should be a way of ensuring an accessible alternative is provided.
alt
Attribute
One of the suggestions against the alt
attribute being required is that WAI-ARIA's aria-labelledby
could be provided instead. WAI-ARIA's aria-labelledby
attribute could provide an accessible alternative, but only when the natural concise text alternative is available elsewhere on the page, such as in the image's description. Most of the time, this is unlikely to be the case — for example, when images are used as navigation items. However, there are examples where aria-labelledby
could be considered an accessible alternative for an image.
Another alternative that could be conveyed from an accessibility architecture to assistive technology is the legend
element used with the figure
element in HTML5.
A text alternative for non-text objects ensures the content is structurally complete and accessible. For the img
element, the accessible alternative can be provided by any of the following.
alt
attributearia-labelledby
attributelegend
element
It is preferable that the accessible alternative always be provided by the alt
attribute, as the value can be suppressed (with alt=""
) when it clashes with other sources for an alternative, such as the legend
element. If it is decided that the alt
attribute should not be required for conformance, then it is recommended that it be mandatory to provide an accessible alternative through one of the preceding three methods and that any one the three methods be required for conformance.
As the img
element is structurally incomplete without a text alternative, HTML5 should make it mandatory for an accessible alternative to be provided; either by making the alt
attribute required, or by providing the aria-labelledby
attribute or the legend
element with the figure
element when the alt
attribute has not been provided.