Skip to content
Tutorials Center
My learning

Topics

Lesson 36 of 122 ยท Images and Media

Image Maps

Make parts of one image clickable with map and area. Learn rect, circle and poly coordinates, accessible alt text, and a responsive SVG alternative.

Sometimes one picture contains several things a visitor might want to click: the rooms on a floor plan, the regions on a map, the parts of a machine. An image map turns areas of a single image into separate links, each with its own destination.

Image maps have been part of HTML since the 1990s, and they still work in every browser. They also have one big weakness on today's responsive web. In this lesson you will build one, learn how to describe shapes with coordinates, make it accessible, and then meet the modern alternative: inline SVG.

The pieces of an image map

An image map needs three things working together:

  1. An ordinary <img> with a usemap attribute.
  2. A <map> element with a name that matches the usemap value.
  3. One <area> element per clickable region inside the <map>.
HTML
<img src="floor-plan.png" alt="Floor plan of the community center"
     width="480" height="300" usemap="#center">

<map name="center">
  <area shape="rect" coords="20,20,220,170" href="reading-room.html" alt="Reading Room">
  <area shape="circle" coords="360,95,65" href="story-circle.html" alt="Story Circle">
</map>

Notice the # in usemap="#center". The value is a hash-name reference: a # followed by the map's name. The <map> element can live anywhere in the page, but putting it right after its image keeps things readable. The <map> itself is invisible; only the image is drawn.

<area> is a void element, like <img>. It behaves like a link: it takes href, and it also supports target, download, rel and referrerpolicy, just as <a> does.

Shapes and coordinates

Each <area> has a shape and a list of coords. Coordinates are measured in CSS pixels from the top-left corner of the image: x grows to the right, y grows downward.

shape coords Meaning
rect x1,y1,x2,y2 Top-left corner, then bottom-right corner
circle x,y,r Center point, then radius
poly x1,y1,x2,y2,x3,y3,โ€ฆ Each corner of a polygon, in order (at least three points)
default (none) The whole image, everywhere not covered by another area

If areas overlap, the first one listed in the source wins. That is why a default area, if you use one, belongs at the end.

A clickable floor plan

The garden is a four-sided polygon: its coordinates walk around the corners, from bottom-left (240,280) to top-left (300,190), top-right (460,190) and bottom-right (460,280). The browser closes the shape automatically.

Finding coordinates. Open the image in any graphics editor and hover over each corner; the editor shows the pixel position. You can also click the image in the browser with a small script that logs event.offsetX and event.offsetY.

Accessibility

An image map can be perfectly accessible, as long as you do the following:

  • Give every <area> with an href an alt. It is required, and it works like link text: screen readers announce it, and it should say where the link goes ("Reading Room", not "rectangle").
  • Give the <img> its own alt describing the image as a whole.
  • Keep areas big enough to hit with a finger. Tiny regions are hard to use on touchscreens.

Areas with an href are focusable, so keyboard users can Tab through them in source order. Try it in the example above: most browsers draw a focus outline around the shape.

Do not rely on the image alone. Visitors cannot see where the clickable regions are until they hover. If the destinations matter, also list them as ordinary text links near the image. That helps everyone, including people using screen magnifiers or search engines.

The big problem: image maps do not scale

Coordinates are fixed pixel values. If CSS makes the image smaller โ€” which is exactly what responsive layouts do โ€” the image shrinks but the areas do not. The hot spots drift away from what they are supposed to cover.

Image maps break when the image shrinks

Clicking almost anywhere selects the Reading Room, because its rectangle now covers most of the shrunken image, while the other three areas now lie completely outside the image and cannot be reached at all. You could recalculate the coordinates with JavaScript on every resize, but there is a cleaner solution.

The modern alternative: inline SVG

SVG describes shapes with coordinates too, but those coordinates live inside a viewBox that scales with the graphic. Wrap each shape in an SVG <a> element and you get clickable regions that stay aligned at any size. As a bonus, you can style hover and focus states with CSS.

A responsive SVG map

Resize the window or change max-width to 240px: the shapes and their clickable areas shrink together. The text inside each <a> gives the link its accessible name, so no separate alt is needed.

Which should you use?

  • Inline SVG is the better choice for new work: it scales, it can be styled and animated, and the shapes are visible to you in the code.
  • Classic image maps still make sense when you have a photo or raster image that you cannot redraw as vectors, and it is shown at a fixed size. You will also meet them in older sites.

You can even combine the approaches: put a photo inside an SVG with the SVG <image> element and draw transparent clickable shapes on top of it. The SVG Paths, Text and Gradients lesson covers the drawing side.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. How do you connect <img usemap="#plan"> to its map?

    The usemap value is a # followed by the map's name, so the map needs name="plan".
  2. 2. What does <area shape="circle" coords="100,80,30"> describe?

    Circle coordinates are the center's x and y, followed by the radius.
  3. 3. Your image map works on desktop, but on phones clicks land on the wrong regions. What is the likely cause?

    Area coordinates never scale with the image. An inline SVG with a viewBox scales its clickable shapes along with the graphic.
  4. 4. Which attribute is required on an area that has an href?

    Every area with an href needs alt text, which works like the link text for screen readers.

Summary

  • An image map is an <img usemap="#name"> plus a <map name="name"> containing <area> elements.
  • shape can be rect (two corners), circle (center and radius), poly (a list of points) or default.
  • Coordinates are pixels from the image's top-left corner; the first matching area wins.
  • Every linking <area> needs alt that names the destination; areas are keyboard-focusable.
  • Area coordinates do not scale with responsive images. Inline SVG with <a> elements is the modern, scalable alternative.

Next up: giving your site an identity in browser tabs and home screens with Favicons and App Icons.