The <image> Tag

Images are specified using the code <img src="filepath" alt="text" />. The image borders and size are best assigned through CSS styling. Images have an intrinsic size which will be used by the browser in the absence of styling information. The alt="text" specification serves many purposes:

  1. It makes information about the image available to visually challenged users.
  2. Some browsers show the text specified in this attribute as a tooltip when the mouse cursor hovers over the image.
  3. Images are intended for human consumption. This attribute provides information that makes the image accessible to search engine spiders. This may help to improve the way the container HTML document is indexed.
  4. Stuffing important keywords into this attribute is a possible technique to improve the search ranking of the document. Although this practice is quite widespread, we are not aware that this does in fact have the desired results. In any case, it is dishonest.
  5. Finally, should the image fail to load the text defined in this attribute will be shown by the browser. This ensures that the page continues to make some sense to the user even in the absence of the image.

Images share some attributes in common with other HTML elements:

The following attributes specific to image elements

Images in IE, particularly page backgrounds, have a tendency to flicker as the user navigates from one page to another on the same website. This happens since by default IE insists on always checking the server for updated versions of the image instead of simply using the cached copy. Client-side solutions to the problem using JavaScript have been suggested but do not always work reliably. Two server-side alternatives that always work are described here.

Finally, it should be noted that image elements can, in the hands of the unscrupulous, pose a security risk. As a general rule, browsers go to great lengths to protect their users. Typically, scripts run on the browser cannot communicate with any domain other than their parent - i.e. the domain from which they were served up. This policy is implemented very strictly, almost ridiculously so. For instance, even an attempt to communicate with an HTTP server residing at the same IP address but serving on a different port will be blocked! When there are legitimate reasons for wanting to do so this limitation can prove to be a real nuisance. Enter the <img> tag

We have used this technique - with our users complete consent - to silently send SMS text alerts using a third party web-to-sms service. However, it could just as easily be used for the unauthorized harvesting of personal information.

Jump To...

Colophon