HTML
HTML introduction
HTML basics
HTML colors
HTML backgrounds
HTML text
HTML font
HTML text formatting
HTML entities
Display tags
HTML links
Email links
Types of links
HTML images
HTML image maps
HTML tables
HTML frames
HTML forms
Fieldset/legend tags
HTML stylesheets
Div/span tags
HTML layout
HTML marquees
HTML multimedia
HTML meta tags
HTML document types
HTML base tag
HTML scripts
URL formatting
Encoding and decoding
HTML summary

Programming

Programming intro
Java

Markup

First webpage guide
XHTML

Style & Layout

CSS

Browser scripting

Javascript
VBScript
AJAX

Server scripting

PHP
ASP

Making money online

Make money online

HTML imagemaps

Images are used as graphical content on webpages, and an image can also link to a document or another resource. But what if you can use one image to link to many different docments and/or resources?

This lesson focuses on:

What is an imagemap?

An imagemap is an HTML concept which enables you to turn one image into many different links. Each area of the image, specified by a set of coordinates, will be a different link.

The <map> tag

The <map> tag is used to create the actual image map. This tag contains an id attribute which specifies a unique name for the image map.

NOTE: You can also use the name attribute at the same time as the id attribute for backwards-compatibility by giving it the same value as you would the id attribute.

Example:

<map id="animalmap" name="animalmap">

</map>

The <area> tag

The <map> tag by itself only declares an image map, it does not define sets of coordinates for different links. This task is achieved through the use of the <area> tag. The <area> tag has no end tag.

Attributes of the <area> tag:

Example:

<area shape="rect" coords="0, 0, 100, 60" 
href="http://allaboutfrogs.org/" 
target="_blank" alt="Learn about frogs" />

<area shape="circle" coords="145, 25, 50" 
href="http://fins.actwin.com/" 
target="_blank" alt="Learn about fish" />

<area shape="poly" coords="210, 30, 230, 5, 260, 30, 240, 60" 
href="http://cats.about.com/" target="_blank" alt="Learn about 
cats" />

Associating an image with an image map

To associate an image with an image map, include the usemap attribute in the <img> tag of the image you want to become an image map. It should be set with a pound (#) sign followed by the name of the image map definition to be used.

Example:

<img src="animals.jpg" usemap="#animalmap" />

An entire imagemap

The entire code for an imagemap definition:

<map name="animalmap">
<area shape="rect" coords="0, 0, 100, 60" 
href="http://allaboutfrogs.org/" target="_blank" 
alt="Learn about frogs" />

<area shape="circle" coords="145, 25, 50" 
href="http://fins.actwin.com/" target="_blank" 
alt="Learn about fish" />

<area shape="poly" coords="210, 30, 230, 5, 
260, 30, 240, 60" href="http://cats.about.com/" 
target="_blank" alt="Learn about cats">
</map />

The code for the image that uses the image map:

<img src="animals.jpg" usemap="#animalmap" width="280" 
height="71" border="0" />

The completed image map:

Learn about frogs Learn about fish Learn about cats Animals

Click on any of the animals to read some information about that animal. (Pages open in a new window)

Examples

Associate an image with an imagemap
This example demonstrates associating an image with an imagemap.

See more imagemap examples

Practice

Online code editor
Practical examples
Practical exercises
Step-by-step tutorials

Reference

Terms glossary
Reference material

Rate this site

Rate this site
Visitor comments