- Home
- /
- Tutorials
- /
- HTML Tutorial
- /
- HTML <map> Tag
HTML Tags
HTML <map> Tag
An image map makes parts of one picture clickable: each country on a map, each room on a floor plan. map holds the clickable areas, area defines each shape, and the image connects to the map with usemap.
Syntax
html
<map name="mapName">
<area shape="shapeType" coords="x1,y1,x2,y2" href="URL" alt="description">
</map>| Attribute | What it does |
|---|---|
| name | The map's name. The image refers to it with usemap="#name", including the #. |
The global attributes such as id and class also work. The shapes themselves are written with the area tag.
Example
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Map Tag Example</title>
</head>
<body>
<h2>Clickable Image Area</h2>
<img src="https://ik.imagekit.io/html5andcss3/lesson-samples/html_map.jpg"
alt="World Map"
usemap="#worldmap">
<map name="worldmap">
<area shape="rect" coords="46,13,170,230" href="https://en.wikipedia.org/wiki/Rectangle" alt="Rectangle">
<area shape="rect" coords="215,38,370,200" href="https://en.wikipedia.org/wiki/Square" alt="Square">
<area shape="circle" coords="107,345,76" href="https://en.wikipedia.org/wiki/Circle" alt="Circle">
<area shape="poly" coords="295,250,372,295,372,383,295,432,218,385,215,295" href="https://en.wikipedia.org/wiki/Hexagon" alt="Poly">
</map>
</body>
</html>The image shows four shapes: a rectangle, a square, a circle and a hexagon. Each one is a separate link to its Wikipedia page. Move the mouse over them and the cursor changes only over the shapes.
How coordinates work
Coordinates are pixels measured from the top-left corner of the image:
shape="rect":coords="x1,y1,x2,y2", the top-left and bottom-right corners.shape="circle":coords="x,y,radius", the center and the radius.shape="poly":coords="x1,y1,x2,y2,...", every corner in order.
The easiest way to find them is to open the image in an image editor and read the pixel position under the cursor.
Browser Support
Chrome | Edge | Firefox | Safari | Opera | IE9+ |
|---|---|---|---|---|---|
| Yes | Yes | Yes | Yes | Yes | Yes |
The big drawback
Coordinates are fixed pixels of the original image. If CSS makes the image smaller on a phone, the clickable areas do not shrink with it, and they no longer line up. For responsive pages, you need a small JavaScript library that rescales the coordinates, or a different approach: an inline SVG with links on each shape scales perfectly.
Good to know
HTML <map> Tag exercises
Create an image map
Make a map named shapes with one rectangle at 0,0,50,50. It goes to /a and is described as Square.
Result
