Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / HTML

map — linked regions on an image

The `map` element works with `img` and descendant `area` elements to create an image map: geometric regions can link to different destinations.

Version: WHATWG HTML Living Standard; index snapshot date recorded separately

Syntax

<img src="image.png" alt="Description" usemap="#navigation">
<map name="navigation">
  <area shape="rect" coords="0,0,100,50" href="#destination" alt="Destination">
</map>

map defines an image map together with img and descendant area elements. The image's usemap="#navigation" references the map's name="navigation". The map itself does not draw the image.

The name attribute is required: it must be nonempty, contain no ASCII whitespace, and be unique among map names in the same tree. If id is also supplied, it must have the same value. Both map tags are required. Its transparent content model means permitted content depends on the parent context.

An area defines a region through shape and coords, and its destination through href. Provide an image description in the img element's alt and destination text in each linked area's alt. An ordinary text link is a useful additional navigation option.

Coordinates use CSS pixels relative to the displayed image; resizing it does not automatically scale the coords values. In the DOM, HTMLMapElement.areas exposes an HTMLCollection of descendant area elements.

Examples

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>Image map</title>
<img width="200" height="80" alt="Blue navigation panel" usemap="#navigation"
     src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='80'%3E%3Cpath fill='royalblue' d='M0 0h200v80H0z'/%3E%3C/svg%3E">
<map name="navigation" id="navigation">
  <area shape="rect" coords="0,0,200,80" href="#destination" alt="Destination">
</map>
<p><a href="#destination">Destination</a></p>
<h2 id="destination">Destination</h2>
</html>

Result

A blue 200 × 80 CSS-pixel image, a Destination text link, and a Destination heading. Activating the image region or text link navigates to #destination.

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources