Image Maps


Introduction to Image Maps

This section describes how to create image maps within your HTML documents. Image maps are graphics which direct the user to resources or locations by clicking on areas of the image. There are two types; server-side and client-side. With both kinds of image map, you display the image as normal using the <IMG> tag. You also provide a map of the graphic to tell the browser which coordinates of the image lead to which location.

Client-side image maps are interpreted by the browser itself, implying that the image map will only function with a compatible browser. Server-side image maps are interpreted by a suitable processing script on the web server (contact your ISP to find find out if they have such a program). This means the user must be on-line for the image map to function, it also means that they will work whichever browser is used. As client-side image maps do not not need to contact the server and run a separate program to function, they are significantly quicker in operation.

Netscape Navigator 2 upwards, Microsoft Internet Explorer 3 upwards and Spyglass Mosaic can all interpret client-side image maps, I would therefore recommend client-side as the way to go, although you must appreciate that you may be alienating users with older browsers. For this reason, and for non-graphical browsers, you should always provide a text-based alternative for your image maps - failing to do this could mean potential readers cannot navigate your site and go elsewhere.

The following sections will guide you in the use of both server-side and client-side image maps.

Specific Markup

<USEMAP>, <ISMAP>, <MAP>, <AREA>

Go to ContentsClient-Side Image Maps

Having chosen a suitable image, you need to display the graphic on the screen and tell the browser that it is an image map. To do this you use the <IMG> element with the USEMAP attribute. You then need to write a MAP file. The map tells the browser which areas of the image lead to which destination. Maps can be written in any text editor and are often included at the end of the <BODY> section of an HTML document. You can also store the map as a separate file, although this is not widely supported.

The following example of an image map lets you jump to a comedy hero of your choice. It will be explained afterwards, so don't use it yet!


<IMG SRC="graphics/nitesky.jpg" BORDER=0 WIDTH=400 HEIGHT=161 ALT="Comic Heroes image map - just an example so no text alternative I'm afraid" USEMAP="#nitesky">


Comic Heroes image map - just an example so no text alternative I'm afraid

The USEMAP attribute contains the location of the map file and uses the same syntax as the HREF attribute of the <A> element. In this case the corresponding map file, nitesky, is contained within the HTML document and a # is used to indicate this. If the map was contained separately in a graphics directory, the USEMAP attribute could read something like USEMAP="graphics/nitesky.map".

The map file, nitesky, is:


<MAP NAME="nitesky">
<AREA	SHAPE="rect"
	COORDS="250,58,386,153"
	TARGET="imagemap_out"
	HREF="http://www.boehme.demon.co.uk/phil/rm/rm.html"
	TITLE="Vic and Bob">
<AREA SHAPE="circle" COORDS="199,44,40" TARGET="imagemap_out" HREF="http://www.harryhill.com/" TITLE="Harry Hill">
<AREA SHAPE="polygon" COORDS="11,129,11,18,63,9,146,25,146,129" TARGET="imagemap_out" HREF="http://www.comedyzone.beeb.com/fastshow/" TITLE="Fast Show">
<AREA SHAPE="default" NOHREF> </MAP>

The map file explained

The elements of the map file are explained below. Use the above example to see how they are implemented.

<MAP></MAP>

These tags contain the map definition and must be used with the NAME attribute.

<AREA>

Used to define part of an image as a live area. Any number of <AREA> tags may be specified. If two areas intersect, the one which appears first in the map definition takes precedence in the overlapping region.

There are a couple of ways to find coordinates of areas on your image. First of all, you could set the graphic as an image map as described above, but use the ISMAP (see server-side) attribute instead of USEMAP. Load it into your browser; move the mouse cursor over the image map and coordinates should be displayed at the bottom of your browser window (assuming you're using a graphical browser). Simply jot down the coordinates corresponding to your hot area and type them into your map file. This procedure can also be performed using a graphics package such as the excellent Paintshop Proexternal link.

Client-side image maps can also be automatically generated using the wonderfully simple CoffeeCup Image Mapper++external link.

Go to ContentsServer-Side Image Maps

Server-Side image maps are quite easy to set up, but require your access provider to have the relevant processing script (contact your ISP to find out). As with client-side image maps, having chosen a suitable image you need to display the graphic on the screen and tell the browser that it is an image map. To do this you use the <IMG> element with the ISMAP attribute. You then need to place the image within a link to the relevant .map file. This is the chief difference between coding for client-side and coding for server-side image maps. The precise syntax of the map file depends on your ISP's image map processing script. As an example you could have a look at the CIX Image Map tutorialexternal link.

The code to display the above example as a server-side image map is:


<A HREF="graphics.nitesky.map">
<IMG SRC="graphics/nitesky.jpg" BORDER=0 WIDTH=400 HEIGHT=161 ALT="Comic Heroes image map - just an example so no text alternative I'm afraid" ISMAP>
</A>


Comic Heroes image map - just an example so no text alternative I'm afraid

Unfortunately the example won't work as my ISP does not have an image map processing script, however if your run your mouse over the image you should see the map coordinates appear at the bottom of the browser window (assuming you're using a graphical browser).

Go to ContentsFrequently Asked Questions

Is the any software available to automatically produce image maps?
CoffeeCup's Image Mapper++external link is a wonderfully simple way to automatically produce client-side image maps.

Go to ContentsUseful References


Sizzling HTML Jalfrezi
ContactPurchase
Page Contents
Previous pageJalfrezi ContentsNext page

Click Here!