CKTIS / HTML
shape — image-map area geometry
The shape attribute on area selects the geometry of an image-map region. The rect, circle, and poly values require coords; default covers the entire image.
Version: WHATWG HTML Living Standard; index snapshot date recorded separately
Syntax
<area shape="rect|circle|poly|default" ...>shape is an enumerated attribute of an area element inside map. An image connects to the map through usemap="#name", referencing its name. The shape defines an interaction region; it does not draw a visible figure.
For rect, supply exactly four integers in coords: x1,y1,x2,y2, where x1 < x2 and y1 < y2. For circle, supply x,y,r: the center and a nonnegative radius; a zero radius produces an empty region. For poly, supply an even number of integers, at least six, describing successive vertices. Coordinates use CSS pixels from the displayed image's top-left corner; resizing the image does not automatically scale them.
default covers the whole image and requires omitting coords. An absent shape or an invalid value means rect, not default. The historical values circ, polygon, and rectangle are recognized but nonconforming for authors.
When regions overlap, the earlier area takes precedence; therefore, place a fallback default region last. Provide descriptive alt text for a link with href.
Examples
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Rectangle and default image-map regions</title>
</head>
<body>
<img id="diagram" width="200" height="100" usemap="#zones"
alt="Two-color diagram with a left region and a fallback region"
src="data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22200%22%20height%3D%22100%22%3E%3Cpath%20fill%3D%22gold%22%20d%3D%22M0%200h200v100H0z%22%2F%3E%3Cpath%20fill%3D%22skyblue%22%20d%3D%22M0%200h100v100H0z%22%2F%3E%3C%2Fsvg%3E">
<map name="zones">
<area shape="rect" coords="0,0,100,100" href="#left" alt="Left region">
<area shape="default" href="#rest" alt="Fallback region">
</map>
<p id="left">Left region</p>
<p id="rest">Fallback region</p>
<script>
const image = document.getElementById('diagram');
const map = document.querySelector('map[name="' + image.useMap.slice(1) + '"]');
const areas = map.querySelectorAll('area');
for (const area of areas) {
for (const type of ['click', 'auxclick']) {
area.addEventListener(type, event => event.preventDefault());
}
}
image.decode().then(() => {
console.log('Loaded image: ' + image.naturalWidth + ' × ' + image.naturalHeight);
for (const area of areas) {
console.log(area.shape + ' | coords: ' + (area.coords || '(none)') + ' | destination: ' + area.hash);
}
});
</script>
</body>
</html>Result
Loaded image: 200 × 100 rect | coords: 0,0,100,100 | destination: #left default | coords: (none) | destination: #rest
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.