CHAPTER 22 · HTML
Image maps: give different parts of one picture different links
An image can contain more than one destination. Build a small map with named regions, learn to read coordinates, and keep ordinary text links available so nobody has to guess where to click.
Download example files (ZIP)When one image link is not enough
The three connected pieces
Coordinates are positions in the image
- 1Img usemap: #campus
- 2Map name: campus
- 3Area shape and coords: the region
- 4Area href and alt: its named destination
Keep equivalent text links and test the measured display size.
Complete program: campus-regions.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Practice Campus Regions</title>
</head>
<body>
<h1>Choose a practice campus place</h1>
<p>Select the rectangle for reading or the circle for meeting.</p>
<img src="images/campus-map.svg" alt="Practice campus plan: reading room rectangle and meeting circle" width="360" height="220" usemap="#campus">
<map name="campus">
<area shape="rect" coords="30,40,130,130" href="#reading" alt="Reading room details">
<area shape="circle" coords="250,90,40" href="#meeting" alt="Meeting spot details">
</map>
<p><a href="#reading">Reading room details</a> or <a href="#meeting">Meeting spot details</a>.</p>
<h2 id="reading">Reading room</h2>
<p>Bring a book and keep your phone silent.</p>
<h2 id="meeting">Meeting spot</h2>
<p>Meet your practice partner before the activity.</p>
</body>
</html>This preview shows the example in a browser. Save the complete code in local files to test links between pages and downloads. Same-page section links work here.
Complete program: polygon-region.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>A Polygon on the Campus Plan</title>
</head>
<body>
<h1>Find the practice help desk</h1>
<p>The triangular mark points to the help desk section.</p>
<img src="images/campus-map.svg" alt="Practice campus plan with a triangular help desk mark" width="360" height="220" usemap="#help-map">
<map name="help-map">
<area shape="poly" coords="120,190,160,150,200,190" href="#help" alt="Help desk details">
</map>
<p><a href="#help">Read the help desk details</a></p>
<h2 id="help">Help desk</h2>
<p>Bring the saved page and explain what you expected to see.</p>
</body>
</html>This preview shows the example in a browser. Save the complete code in local files to test links between pages and downloads. Same-page section links work here.
Overlapping areas and the default shape
Image size and mobile limits
Test more than the mouse
Problem and solution: the clickable place is beside the drawing
Common mistakes and useful tips
Matching usemap to an unrelated id instead of the map name. Putting # inside the map's name value. Omitting alt on linked area elements. Reversing rectangle corners or giving a circle four values. Changing coords and expecting the image drawing to change. Scaling the picture without checking the regions. Offering no visible text alternatives for important navigation.
Practice questions
How does usemap="#places" connect to a map? What are the four values for a rectangle? What does the third value of circle coords mean? What should a linked area's alt describe? Will fixed coordinates automatically follow an image resized with CSS? Save the campus example, test both regions and text alternatives, then change one coordinate. Explain what changed and what stayed the same.
Check your practice answers
It refers to map name="places" in the document. The top-left x,y pair followed by the bottom-right x,y pair. The radius, measured from the centre to the edge. The destination or purpose of that region's link. No. A responsive design needs an appropriate scaling solution or another navigation approach. Use the supplied image at its stated dimensions. A coordinate edit changes the invisible region; it does not alter the image file. Restore sensible values and check keyboard access too.
Interview questions
How does an image map differ from an ordinary image link?
Why give alt to each linked area as well as the image?
What makes fixed image maps difficult on small screens?
When would you avoid an image map?
Quick revision
Img usemap refers to map name; area supplies each region. Coordinates describe positions, not a new drawing. Keep linked-region names and equivalent visible links clear. Test size changes, region boundaries and keyboard navigation.