HTML image map

An image map turns parts of a single image into separate links using fixed pixel coordinates. That fixed part is the catch, and it is why most modern diagrams use absolutely positioned links or inline SVG instead.

An HTML image map is a set of clickable regions drawn over one image, defined by pixel coordinates in a <map> element and linked to the image with usemap.

One picture, several destinations. A floor plan where each room links to a different page, a product photo where each part opens its own spec.

A floor plan image in a browser. The cursor sits over one room and the status bar shows a different URL than the room beside it.
A floor plan image in a browser. The cursor sits over one room and the status bar shows a different URL than the room beside it.

The two tags involved

The image carries a usemap attribute. The map carries a matching name. Inside the map, each <area> is one clickable region.

<img src="floorplan.png" usemap="#rooms" alt="Office floor plan">

<map name="rooms">
  <area shape="rect" coords="12,40,180,220" href="/rooms/studio" alt="Studio">
  <area shape="circle" coords="320,150,60" href="/rooms/booth" alt="Recording booth">
  <area shape="poly" coords="400,30,520,30,520,180,460,220,400,180"
        href="/rooms/kitchen" alt="Kitchen">
</map>

The # in usemap is required. Without it the map is not found and every region is dead, which is the single most common reason an image map does nothing at all.

What the coordinates mean

shape coords Read as
rect x1,y1,x2,y2 Top left corner, then bottom right corner
circle x,y,r Centre point, then radius
poly x1,y1,x2,y2,... Corner after corner, closed automatically
default none Everything not covered by another area

Every number is a pixel measured from the top left of the image at its natural size. Not the displayed size. That distinction is the whole problem.

Why the regions drift on a responsive page

If your CSS says img { max-width: 100%; }, the image shrinks on a narrow screen. The coordinates do not shrink with it.

The result is a page where the rooms are clickable slightly up and to the left of where they appear, and on a phone the offset is large enough that every region is wrong.

The same floor plan in a narrow window. The highlighted clickable area sits visibly away from the room it belongs to.
The same floor plan in a narrow window. The highlighted clickable area sits visibly away from the room it belongs to.

Browsers do not rescale coords for you, and there is no CSS property that fixes it. You have three real options.

  1. Keep the image at a fixed width. Honest, and fine for an internal diagram nobody opens on a phone.
  2. Recalculate in JavaScript. Listen for resize, multiply every coordinate by img.clientWidth / img.naturalWidth, rewrite the coords strings. This works and is about fifteen lines.
  3. Drop map entirely. Use percentage positioned links, or inline SVG. Both scale for free.

The replacement most people end up using

A wrapper with position: relative, and anchors positioned in percentages on top of it. Percentages are of the wrapper, so they follow the image at every size.

<div style="position:relative; max-width:640px">
  <img src="floorplan.png" alt="Office floor plan" style="width:100%; display:block">
  <a href="/rooms/studio"
     style="position:absolute; left:2%; top:18%; width:26%; height:40%"
     aria-label="Studio"></a>
  <a href="/rooms/booth"
     style="position:absolute; left:44%; top:30%; width:18%; height:28%"
     aria-label="Recording booth"></a>
</div>

Rectangles only, unless you add clip-path for odd shapes. In exchange the regions stay put at every width.

You also get focus outlines that work, and hover styling written in ordinary CSS, which <area> does not really offer. A CSS hover transition on those anchors makes the regions visible on pointer devices.

The percentages are worked out once from the original image. Divide each pixel coordinate by the image width or height and multiply by a hundred. A spreadsheet does the whole set in a minute.

Browser dev tools with one of the overlay anchors selected, its percentage box drawn over the image.
Browser dev tools with one of the overlay anchors selected, its percentage box drawn over the image.

When inline SVG is the better answer

If the diagram is vector art rather than a photo, skip the bitmap. Put the SVG in the HTML and wrap each shape in an <a>.

<svg viewBox="0 0 640 400" role="img" aria-label="Office floor plan">
  <a href="/rooms/studio"><rect x="12" y="40" width="168" height="180" fill="#2a3242"/></a>
  <a href="/rooms/booth"><circle cx="320" cy="150" r="60" fill="#334155"/></a>
</svg>

The viewBox handles scaling, so the coordinates keep their meaning at any size. You also get per shape hover fills, and you can change the colour from CSS rather than exporting a second file.

Accessibility, briefly

  • Each <area> needs an alt. It is the link text, not decoration. Empty alt on a linked area leaves a screen reader reading the URL.
  • The parent <img> still needs its own alt describing the picture as a whole.
  • Areas are keyboard focusable in order of appearance, so write them in reading order.
  • For the overlay approach, use aria-label on each anchor since there is no visible text inside it.

Whichever technique you pick, the regions should not be the only route to those pages. A plain list of the same links underneath costs nothing and covers every reader who cannot use the picture.

Checking it before you send it

Image maps fail quietly. The page looks correct and the clicks land in the wrong place, so nobody reports it as broken.

The same page pasted into a NOS document. The image and its clickable regions render as written.
The same page pasted into a NOS document. The image and its clickable regions render as written.

Open the page at three widths and click one region at each. If the image file sits next to the HTML rather than being embedded, it will not travel with the file, and the map ends up floating over nothing.

To hand the diagram to someone, paste the HTML into a NOS document and send the link. The regions keep working and the page renders as written.

The address stays the same when you move a room, so a corrected coordinate is an edit rather than a second email with a second copy of the file. Turning HTML into a link is that step.

When an image map is the wrong tool

Three cases where the effort is better spent elsewhere.

  • The regions are already rectangles in a grid. Use a plain layout of linked cards with the image split into pieces. Easier to label, easier to reorder.
  • The picture is a chart. Charts want live data, not a frozen picture with hotspots. A chart shared as a link stays current.
  • There are more than about a dozen regions. Maintaining that many coordinate sets by hand goes wrong quickly. Generate them, or move to SVG where each shape carries its own geometry.

An image map remains a good fit for one thing in particular: a photograph or a scanned plan where the regions follow real objects that cannot be rebuilt as markup.

Questions people ask

Do image maps still work in browsers?

Yes. The map and area elements are still part of HTML and every current browser supports them. Nothing is deprecated. The problem is not support, it is that the coordinates are measured in pixels of the original image and do not rescale when the image does.

How do I make an image map responsive?

Either recalculate the coordinates in JavaScript whenever the image resizes, or stop using map and area. Overlaying percentage positioned anchor tags on the image, or using inline SVG with clickable shapes, both scale on their own with no script.

Are image maps bad for accessibility?

They are fine if each area has an alt attribute describing where it leads. Screen readers announce those areas as links. An image map with no alt text on the areas is a group of unlabelled links, which is worse than a plain list.

Can I share a page with an image map as a link?

Yes. Paste the HTML into a NOS document and it renders with the clickable regions intact, then copy the share link. The image itself needs to be embedded or on a full address, otherwise the picture is missing and the regions click on nothing.

Keep reading