image-map
Modern responsive image map with percentage-based coordinates, rich HTML tooltips, keyboard navigation, and progressive enhancement.
Overview
The <image-map> component replaces native HTML <map>/<area> with percentage-based coordinates that scale responsively. Areas are defined as <map-area> children with rich HTML tooltip content, full keyboard navigation, and progressive enhancement.
Markup Pattern
Place an <img> as a direct child of <image-map>. The component adopts it and overlays an SVG hit-testing layer. Each <map-area> defines a hotspot region — its inner HTML becomes the tooltip content.
Alternatively, src and alt attributes on <image-map> itself can create the image, but placing <img> as a child gives better progressive enhancement.
Coordinate System
All coordinates are percentages (0–100) of the rendered image dimensions — not pixels. Values are unitless numbers separated by spaces or commas. The SVG overlay uses viewBox="0 0 100 100" so percentage coordinates map directly to SVG units with no runtime conversion.
| Shape | Coords format | Description |
|---|---|---|
rect |
x1 y1 x2 y2 |
Top-left and bottom-right corners |
circle |
cx cy r |
Centre point and radius (radius is % of image width) |
poly |
x1 y1 x2 y2 ... |
Series of points (minimum 3), auto-closes |
All Shapes Demo
Tooltip Content
The inner HTML of each <map-area> becomes the tooltip content. Use any HTML: headings, paragraphs, lists, images, links.
Tooltip modes
By default, tooltips show on hover (tooltip="hover"). Set tooltip="click" for click-to-toggle, which is better for tooltips with interactive content like links. Set tooltip="none" to disable tooltips entirely.
CSS Custom Properties
| Property | Default | Description |
|---|---|---|
--map-area-color |
oklch(60% 0.2 250 / 0.08) |
Default area fill (subtle hint) |
--map-area-color-hover |
oklch(60% 0.2 250 / 0.35) |
Hover/focus area fill |
--map-area-stroke |
oklch(60% 0.2 250 / 0.3) |
Default area outline stroke |
--map-tooltip-bg |
oklch(15% 0 0 / 0.92) |
Tooltip background |
--map-tooltip-color |
white |
Tooltip text colour |
--map-tooltip-radius |
0.5rem |
Tooltip border radius |
--map-tooltip-max-width |
20rem |
Tooltip maximum width |
Attributes
<image-map>
| Attribute | Type | Description |
|---|---|---|
src |
string | Image URL (fallback if no child <img>) |
alt |
string | Image alt text (fallback if no child <img>) |
aria-label |
string | Accessible label for the map group (defaults to img alt) |
<map-area>
| Attribute | Type | Required | Description |
|---|---|---|---|
shape |
string | Yes | rect, circle, or poly |
coords |
string | Yes | Space or comma-separated percentage values (0–100) |
label |
string | Yes | Accessible name for the hotspot |
href |
string | No | Navigation target. Creates an <a> focus anchor |
target |
string | No | Link target (_blank, etc.) |
tooltip |
string | No | hover (default), click, or none |
disabled |
boolean | No | Suppresses interaction and tooltip |
Events
| Event | Detail | Description |
|---|---|---|
image-map:area-enter |
{ area } |
Pointer or focus entered an area |
image-map:area-leave |
{ area } |
Pointer or focus left an area |
image-map:area-activate |
{ area } |
Area clicked or Enter pressed |
Keyboard Navigation
| Key | Action |
|---|---|
| Tab | Move focus between area anchors |
| ↓ / → | Focus next area |
| ↑ / ← | Focus previous area |
| Enter / Space | Activate area (follow link or dispatch event) |
| Escape | Dismiss tooltip |
Accessibility
Each <map-area> generates a focusable anchor element (<a> when href is set, <button> otherwise) with aria-label matching the area’s label attribute. The SVG overlay is aria-hidden — it handles only pointer hit-testing. The tooltip uses role="tooltip" and aria-live="polite" for screen reader announcements.
The host element uses role="group" with an aria-label derived from the image alt text.
Progressive Enhancement
Touch Behaviour
On touch devices with tooltip="hover", a two-tap pattern is used: the first tap shows the tooltip, the second tap navigates (if href is set). For tooltip="click", tapping toggles the tooltip on/off. Press Escape or tap elsewhere to dismiss.
Related
- tool-tip — General-purpose tooltip component
- geo-map — Interactive geographic maps
- compare-surface — Before/after image comparison
- map — Native HTML image map (pixel-based)
- area — Native HTML area element