alt attribute

From Wikipedia, the free encyclopedia
  (Redirected from Alt text)
Jump to navigation Jump to search

The alt attribute is the HTML attribute 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.

The alt attribute is 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. Additionally, it substitutes the image when copy-pasted as text and makes images more machine-readable, which improves search engine optimization.[1] Every image should have an alt attribute to be accessible, but it need not contain text. It can be an empty or null attribute: alt="".[2]

The attribute was introduced in the HTML 1.2 draft [3] to support text-based browsers and in HTML 4.01 was required for the img and area tags.[4] It is optional for the input tag and the deprecated applet tag.


In the sky flies a red flag with a white cross whose vertical bar is shifted toward the flagpole.

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="">
This paragraph as seen in the text-based Lynx web browser, which displays the alt text instead of the image.

A visually impaired reader using a screen reader such as Orca will hear the alt text in place of the image. A text-based web 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 or has configured the browser not to display images, or if the browser was unable to retrieve or to decode the image.

An alternative alt attribute value would be "The Danish flag".

Common misconceptions[edit]

The alt attribute does not always have to literally describe the contents of the image. Keep in mind the purpose and context of the image and what would be useful to someone who cannot see it. The alt attribute is supposed to be an alternative for the image, usually stating its purpose. For example, an image of a warning sign should not have alt text “a triangle with a yellow background, black border and an exclamation mark”, but simply “Warning!”—unless, of course, the image's purpose is to show what the warning symbol actually looks like.

IE7 renders the alt attribute as tooltip

Internet Explorer 7 and earlier render text in alt attributes as tooltip text, which is not standards-compliant.[5][6] This behavior led many web developers to misuse alt when they wished to display tooltips containing additional information about images,[7] instead of using the title attribute that was intended for that use.[8] As of Internet Explorer 8 alt attributes no longer render as tooltips.[9]

The alt attribute is commonly, but incorrectly, referred to as the "alt tag".[6][10][11]

Decorative images[edit]

The W3C recommends that images that convey no information, but are purely decorative, be specified in CSS rather than in the HTML markup.[12] However, it may sometimes be necessary to include a decorative image as an HTML img tag. In this case, if the image truly does not add to the content, then a blank alt attribute should be included in the form of alt="". This makes the page navigable for users of screen readers or non-graphical browsers. If (in breach of the standard) no alt attribute has been supplied, then browsers that cannot display the image will still display something there, e.g. the URL of the image, or a fixed text string.

See also[edit]


  1. ^ "Google Images SEO Best Practices | Search Central".
  2. ^ "Alternative Text", WebAIM, last updated 3 September 2015.
  3. ^ Berners-Lee, Tim; Connolly, Daniel (June 1993). "Hypertext Markup Language (HTML) Internet Draft version 1.2". IETF IIIR Working Group. Retrieved 18 September 2010.
  4. ^ "13 Objects, Images, and Applets". World Wide Web Consortium. 24 December 1999.
  5. ^ "Why doesn't Mozilla display my alt tooltips?". Archived from the original on 15 October 2008. Retrieved 22 July 2009.
  6. ^ a b Anne van Kesteren (16 December 2004). "Alt attribute (alt tag, alt tooltip)". Retrieved 22 July 2009.
  7. ^ Bug 25537 - Alt text is not displayed as a tooltip over <img>, Mozilla bugzilla
  8. ^ W3C HTML WG (24 December 1999). "7.4.3 The title attribute". HTML 4.01 Specification. W3C. Retrieved 22 July 2009.
  9. ^ "What's New in Internet Explorer 8 – Accessibility and ARIA". MSDN. Microsoft. Archived from the original on February 28, 2009. Retrieved 22 July 2009.
  10. ^ Roger Johansson (7 November 2005). "It's alt attribute, not alt tag". 456 Berea Street. Archived from the original on 8 June 2009. Retrieved 22 July 2009.
  11. ^ Tommy Olsson (20 July 2004). "Alt tags". The Autistic Cuckoo. Archived from the original on 25 December 2007. Retrieved 22 July 2009.
  12. ^ W3C. "Embedded content - HTML 5".


External links[edit]