alt attribute
The alt attribute is used in HTML and XHTML documents to specify alternative text (alt text) that is to be rendered when the element to which it is applied cannot be rendered. It is also used by "screen reader" software so that a person who is listening to the content of a webpage (for instance, a person who is blind) can interact with this element. In HTML 4.01, the attribute is required for the img and area tags. It is optional for the input tag and the deprecated applet tag.
The syntax of the alt attribute is:
<img alt="...">
<area alt="...">
or
<input alt="...">
Contents |
[edit] Example
Here is an image for which the alt attribute is "In the sky flies a red flag with a white cross whose vertical bar is shifted toward the flagpole."
The HTML for this image might be something like the following:
<img alt="In the sky flies a red flag with a white cross whose vertical bar is shifted toward the flagpole." src="http://upload.wikimedia.org/wikipedia/commons/thumb/8/83/Dannebrog.jpg/180px-Dannebrog.jpg" width="180" height="135" />
A visually impaired reader using a screen reader such as Orca will hear the alt text in place of the image. A text browser such as Lynx will display the alt text instead of the image. A graphical browser typically will display only the image, and will display the alt text only if the user asks it to show the image's properties. Many graphical browsers can be configured to show the alt text instead of the image.
An alternative alt attribute value would be "The Danish flag".
[edit] Common misconceptions
The alt attribute does not always have to literally describe the contents of the image [1]. Keep in mind what would be useful to someone who cannot see the image. The alt attribute is supposed to be an alternative for the image, usually stating its purpose. For example an image of a warning sign alt-text might not be useful if it simply says "a triangle with a yellow background, black border and an exclamation mark". It would be more useful by simply saying "Warning Symbol". (If you just put "Warning!", a user might wonder what that meant. Is their screen reader giving them a warning? Or what if the purpose of the image was to actually show what the warning symbol looks like? Then you could use a literal description.
Internet Explorer 7 and earlier render text in alt attributes as tooltip text in standards non-compliant manner.[1][2] This behavior led many web developers to misuse alt when they wished to display tooltips containing additional information about images,[3] instead of using the title attribute that was intended for that use.[4] As of Internet Explorer 8 alt attributes no longer render as tooltips.[5]
The alt attribute is commonly, but incorrectly, referred to as the "alt tag".[2][6][7]
[edit] See also
[edit] References
- ^ "Why doesn’t Mozilla display my alt tooltips?". https://developer.mozilla.org/en/Mozilla_Web_Developer_FAQ#Why_doesn.e2.80.99t_Mozilla_display_my_alt_tooltips.3f. Retrieved 22 July 2009.
- ^ a b Anne van Kesteren (16 December 2004). "Alt attribute (alt tag, alt tooltip)". http://annevankesteren.nl/2004/12/alt-attribute. Retrieved 22 July 2009.
- ^ Bug 25537 - Alt text is not displayed as a tooltip over <img>, Mozilla bugzilla
- ^ W3C HTML WG (24 December 1999). "7.4.3 The title attribute". HTML 4.01 Specification. W3C. http://www.w3.org/TR/html4/struct/global.html#h-7.4.3. Retrieved 22 July 2009.
- ^ "What's New in Internet Explorer 8 – Accessibility and ARIA". MSDN. Microsoft. http://msdn.microsoft.com/en-us/library/cc288472.aspx#access. Retrieved 22 July 2009.
- ^ Roger Johansson (7 November 2005). "It’s alt attribute, not alt tag". 456 Berea Street. http://www.456bereastreet.com/archive/200511/its_alt_attribute_not_alt_tag. Retrieved 22 July 2009.
- ^ Tommy Olsson (20 July 2004). "Alt tags". The Autistic Cuckoo. http://www.autisticcuckoo.net/archive.php?id=2004/07/20/tags-elements-attributes. Retrieved 22 July 2009.
[edit] External links
- How to specify alternate text from the HTML 4.01 specification
- Providing text equivalents for images from Dive Into Accessibility
- Guidelines on alt texts in
imgelements by Jukka Korpela - Alternative text for images: the alt attribute by Estelle Weyl
- Mini-FAQ about the alternate text of images by Ian Hickson
- Handy bookmarklets for alt attribute management [2] [3]