Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / HTML

coords: clickable geometry in an image map

Match coordinate lists to the chosen shape and the displayed image.

Version: HTML Living Standard

Syntax

<area shape="rect" coords="0,0,50,100" href="#left" alt="Left">

On an image-map area, coords defines geometry in CSS pixels relative to the image’s top-left corner. rect takes left, top, right, bottom; circle takes center x, center y and a nonnegative radius; poly takes at least three coordinate pairs. A default area covers the image and must omit coordinates.

A rectangle needs increasing horizontal and vertical edges. Coordinates are not percentages and must remain consistent with the rendered image size. Connect the image to its map and give linked areas meaningful alternative text. An area is a link region, not a visible shape drawn by these numbers.

The fixture uses a 100-by-100 image with a rectangle and circle. Two real pointer clicks at different positions activate different links; their handlers record the targets without navigating. This verifies hit testing rather than merely reading an attribute.

Examples

<!doctype html><meta charset="utf-8">
<img id="image" src="/map.svg" width="100" height="100" usemap="#choices" alt="Blue rectangle and orange circle">
<map name="choices"><area shape="rect" coords="0,0,50,100" href="#left" alt="Left"><area shape="circle" coords="75,50,20" href="#right" alt="Right"></map>
<p>Click the image at (25, 50), then (75, 50), relative to its top-left corner.</p><output id="result"></output>
<script>
const hits = [];
document.querySelectorAll('area').forEach(area => area.addEventListener('click', event => {
  event.preventDefault(); hits.push(area.hash.slice(1));
  document.querySelector('#result').textContent = hits.join(',');
}));
</script>

Result

left,right

The two clicks use positions relative to the image, with no assumed page offset.

Sources