- Image Map
HTML image maps are defined with the <map> tag. An image map makes specific areas of an image clickable, so each area works as a link to a different destination. This technique is useful for building complex navigation systems or interactive graphics on a web page.
By defining different shapes (rectangles, circles and polygons) on an image, each with its own link, developers can create lively interactive content that improves the user experience and navigation.
11.1. Use of Image Maps
Image maps are useful for building complex navigation systems, interactive diagrams or engaging visual experiences that increase user engagement and interaction on a web page.
They are useful for creating interactive graphics by defining clickable areas within an image. Users can interact with different parts of the image, and each part triggers a specific action or link.
11.2. HTML <map> Tag
The <map> tag is used to create a client-side image map, which turns specific areas of an image into interactive elements. Users can click different areas of the image to trigger different actions.
The <map> element is a container for <area> elements, each of which defines a clickable area with its own attributes.
Syntax:
When used with the <img> tag, the <map> tag links the image to its image map. This lets web developers create lively, interactive content by defining specific clickable areas within an image.
11.3. Defining Areas (Shapes) in Image Maps
The <area> tag is used inside the <map> tag to define the clickable areas on an image. It sets the shape, the coordinates and the linked action for each clickable area.
Syntax:
1. Rectangular AreaYou can define a rectangular shape by setting the shape attribute to rect. A rectangle needs the coordinates of its top-left corner and its bottom-right corner, which you set in the coords attribute.
Syntax:
- x1, y1 − Coordinates of the top-left corner.
- x2, y2 − Coordinates of the bottom-right corner.
You can define a circular shape by setting the shape attribute to circle. A circle needs the coordinates of its center (x, y) and its radius (r), which you set in the coords attribute.
Syntax:
- x, y − Coordinates of the circle's center.
- r − Radius of the circle.
You can define a polygon shape by setting the shape attribute to poly. A polygon needs a series of coordinates that together form the shape, which you set in the coords attribute.
Syntax:
These shapes let you build interactive image maps that increase user engagement by linking different actions to specific areas of an image.
Source Code: shape.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>ImageMap Example</title>
</head>
<body>
<h2 align="center">Image Map Example</h2>
<p align="center">
<img src="shape.png" usemap="#image-map">
<map name="image-map">
<area shape="rect" coords="65,121,438,343" href="rectangular.html">
<area shape="circle" coords="646,220,122" href="circle.html">
<area shape="poly" coords="868,176,998,80,1131,178,1081,333,918,332" href="polygon.html">
</map>
</p>
</body>
</html>Result:
Source Code: rectangular.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Rectangular Area</title>
</head>
<body>
<h2 align="center">Rectangular Area</h2>
<p align="center">
<img src="rect.png" width="50%">
</p>
</body>
</html>Result:
Source Code: circle.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Circle Area</title>
</head>
<body>
<h2 align="center">Circle Area</h2>
<p align="center">
<img src="circle.png" width="50%">
</p>
</body>
</html>Result:
Source Code: polygon.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Polygon Area</title>
</head>
<body>
<h2 align="center">Polygon Area</h2>
<p align="center">
<img src="polygon.png" width="50%">
</p>
</body>
</html>Result:
Watch the video:






