How should Web browsers render alternate text?
Recently, Steve Faulkner performed a detailed comparison of how the leading Web browsers render alternate text that revealed non-uniform behaviour across browsers. Steve called for the HTML5 team to document a recommended behaviour. This article adds to Steve's work and makes a case for what I believe to be the correct way to render alternate text.
What is alternate text?
The <img> element contains content that can be represented visually and textually. The src attribute provides visual content and the alt attribute provides textual content. For example:
<img src="visual content" alt="textual content" />
The content in the src and alt attributes must convey equivalent meaning. In other words, alternate text is an equivalent substitute for visual content and visual content is equivalent substitute for alternate text.
Should alternate text be displayed when images are not rendered?
Silly question, right? Not so silly considering that a good deal of the time, Chrome and Safari do not render alternate text for images. The first example of this, described by Roger Johansson, is when the browser fails to download the image and its alternate text does not fit into the space the image would have occupied, or the space of the alternate text plus the space for an error icon. So if you start with the following markup:
<html><head><title>Test of rendering alt text</title></head><body><p>Press <img src="rss.png" alt="the RSS button" /> to get recent articles.</p></body></html>
When the image cannot be downloaded, Safari will render the preceding markup as follows:

The second example is when users turn off image rendering. To turn off image rendering in Chrome for Windows, pass the -disable-images command line argument to chrome.exe like this:
- C:\Users\Alexander\AppData\Local\Google\Chrome\Application\chrome.exe -disable-images
To turn off image rendering in Safari, enable the Develop menu under the Advanced settings. Then select Disable Images from the Develop menu.
When the image can be downloaded but the user turns off image rendering, the previous markup example will be rendered as follows:

Of course the correct behaviour is to render alternate text, and Firefox renders the previous markup example best of all as shown in the following screen shot:

Should alternate text be displayed inside the image outline?
In the following markup, width and height attributes are specified:
<html><head><title>Test of rendering alt text</title></head><body><h1><img src="welcome.png" width="100" height="100" alt="Welcome to my Web site!" /></h1></body></html>
When the image cannot be downloaded, Web browsers will render the preceding markup as follows:

The width and height attributes are meant to apply to visual content of the <img> element, not to the textual alternate content. It is therefore incorrect behaviour to apply width and height to textual alternate content. As a result of such behaviour, all browsers will cut-off content or will not display content if content does not fit into the outline frame of the image. Simply rendering the textual content in place of the visual content would be the preferred solution as shown in the screen shot below:

Should an icon be displayed to indicate the content is from an image?
When a user turns off image rendering and the image can be downloaded by the browser, Internet Explorer displays an information icon next to the alternate text to indicate that the content displayed is from an image, as seen in the screen shot below:

This information icon interrupts the flow of content. When the information icon is combined with a frame around the alternate text and rendered in a different font, it makes it difficult to read the content of the document.
Should alternate text be displayed differently when image rendering is turned off, versus failure to download images?
When the browser fails to download an image, IE will display a red cross next to the alternate text to indicate an error, as seen in the screen shot below:

Firefox will also render an error icon if the width and height attributes are present as shown in the following screen shot:

Should error information be displayed in the document itself? If it were important to notify the user of a failed image download, wouldn't it be more appropriate to bring this to the user's attention using the status bar or the information bar?
Conclusion
If there is agreement that textual alternate content for an image is an equivalent replacement for the visual content of an image, then the textual alternate content alone should replace visual content when it is not rendered.
Comments are closed for this article.