Saturday, 28 February 2015

ADDING ALTERNATIVE TEXT TO IMAGE

Images can turn a simple text-only web page into a glorious visual feast. But what happens if someone is reading your webpage using a text-only browser? What if she has image loading turned off so that all you carefully crafted graphics appear as generic icons? All of a sudden, that visual feast doesn’t look quite as glorious.

There’s simple solution to this problem. By using the alt attribute of the <img> tag, you can substitute something meaningful in place of the on browsers that cannot display it.

In text-only browsrs, such as Lynx, graphics that are specified using the <img> tag inn the original file usually are displayed as the word IMAGE with square brackets around it. Like this: (IMAGE) for your visitors who are using text –only web browsers, or who have graphics turned off on their browsers. The alt attribute contains a string with the text you want to substitute for the graphic:
<img src = “my image. Gif” alt = “[picture of a cat]”/>

Most browsers interpret the string you include in the alt attribute as a literal string. That is, if you include an HTML tags in that string, they’ll be printed as-is rather than be in parsed and displayed as HTML code. Therefore, you can’t use whole blocks of HTML code as a replacement for an image – just a few words or phrases.

I bring up image alternatives now for good reason. Alternatives to images are optional in earlier version of HTML, but they’re mandatory in HTML 4.01 strict and XHTML 1.0 specifications. If there’s no appropriate alternative text for an image, you can simply leave it empty, like this: alt=””.

No comments:

Post a Comment