The alt attribute is for images only

The alt attribute is used to provide alternate text for HTML elements that use images. The alternate text is used when an image cannot be seen (because the user can’t see) or when it cannot be rendered (because the display of images is disabled, the browser does not support images, the image is corrupt, the image’s URL is incorrect, etcetera).

In HTML 4.01 Strict the alt attribute is valid only for the following three elements:

The alt attribute is only relevant for input elements (graphical submit buttons) that also have a type attribute whose value is image.

For img and area elements, the alt attribute is required. It is optional for input elements though alternative text should always be provided for graphical submit buttons.

Sometimes I see people use alt attributes for other elements, such as links. I think in most such cases the author is really looking for the title attribute, which can be used to provide additional information about an element. More detailed descriptions of these attributes and their use can be found in The alt and title attributes.

This post is a Quick Tip. Background info is available in Quick Tips for web developers and web designers.

Translations

This article has been translated into the following languages:

Posted on February 16, 2009 in (X)HTML, Accessibility, Quick Tips

Comments are disabled for this post (read why), but if you have spotted an error or have additional info that you think should be in this post, feel free to contact me.