HTML Image Maps
Image maps are images with clickable areas (sometimes referred to as "hotspots") that usually link to another page.
If used appropriately, image maps can be an effective means for your users to find out more information about an item represented in the image. They can click different parts of the image to open a web page related to that part.
To create an image map:
-
Add the
<img>
TagEmbed the image into the page using the usual method (via the
<img>
element).Of course, the image must be available on the web first. You can either upload it or reference an existing image. It can be a photo, icon, logo, stock image, etc. Any image is fine.
-
Add the Map
Use the HTML
<map>
tag to create a map with a name. Inside this tag, you will specify where the clickable areas are with the HTML<area>
tag. -
Link them with the
usemap
AttributeThis bit links the map with the image.
Add the
usemap
attribute to the<img>
tag. The value must be the name of the map, preceded by a hash (#
) symbol.For example if the map has
name="pluto"
then you should useusemap="#pluto"
in the image.
Image Map Example
OK, compared to our previous lessons, this code is looking quite complex. However, once you study it, it is not that complex. All we are doing, is adding an image, then we are creating a map with coordinates. The hardest part is getting all the coordinates right.
In our example, we use the <area>
tag in conjunction with the shape
and coord
attributes. These accept the following attributes:
shape |
Defines a shape for the clickable area. Possible values:
|
coords |
Specifies the coordinates of the clickable area. Coordinates are specified as follows:
|
You can use the above attributes to configure your own image map with as many shapes and clickable regions as you like.