Interactive SVG infographics that work on touch and keyboard

Design SVG infographics with hover, focus and tap states, keyboard access, forgiving hit areas, tooltips and a detail panel, without relying on hover alone.

An interactive infographic is an SVG where shapes respond to the reader: a region highlights, a label appears, a panel fills with detail. SVG suits this because every shape is a DOM element you can style and listen to. The risk is building something that only works for a mouse. This guide covers the structure and the habits that keep an infographic usable on phones, with a keyboard, and with assistive technology.

Start with content that works without interaction

Decide what the infographic says before deciding how it moves. Every fact that appears only on hover is invisible to touch users, keyboard users and anyone whose script fails to load. A solid baseline:

  • Show the key values as visible text or labels in the default state.
  • Treat hover, focus and tap as ways to see more detail, not the only way to see anything.
  • Provide the same data in a text form nearby, such as a short summary or a table.

Build a structure you can address

Give each interactive region its own group and attach its data to it. A script, a stylesheet and a screen reader can all work from this one structure.

Click into the preview and press Tab. Each region takes focus and shows its label, using the same styles as hover.

Points worth noting in that markup:

  • tabindex="0" makes an SVG element focusable and places it in the normal Tab order. MDN lists the SVG tabindex attribute as widely available.
  • <title> gives the element a short accessible name, and browsers usually show it as a tooltip. MDN says it should be the first child of its parent. It is a convenience, not a full solution, because touch devices generally cannot hover a tooltip into view.
  • pointer-events: none on the tip stops the label from stealing hover from the shape under it.
  • :focus-visible shows a focus ring when the browser decides it should be visible, which keeps the ring for keyboard users without flashing it on every mouse click. MDN notes the ring should meet the 3:1 non-text contrast requirement of WCAG 2.1 SC 1.4.11.

Do not rely on hover

Touch screens usually have no convenient hover. The hover media feature reports whether the primary input can hover, and MDN recommends wrapping hover styles in @media (hover: hover) to avoid sticky hover states, where a tapped element stays highlighted after the finger lifts. The example above does that. It also gives focus its own rule, so tapping or tabbing to a region still reveals the label.

For a reveal that must also survive on touch, use a click or tap to select a region and keep it selected. A selected state also gives you something to describe in a text panel, covered below.

Make the tap and click targets forgiving

SVG hit testing follows the painted shape by default. MDN’s pointer-events page explains that with the default visiblePainted behavior, a shape with fill="none" can be clicked only on its stroke, so clicks in the middle pass through. Thin lines are hard to hit, especially on a phone.

Two fixes:

  • Use pointer-events: fill or all so a shape’s interior responds even if it is unfilled.
  • Draw an invisible, larger shape on top of thin elements to act as a hit area.
<g class="route" tabindex="0">
  <path d="M10 80 C 60 10, 120 10, 170 80" fill="none" stroke="#1f3fe0" stroke-width="2"/>
  <path d="M10 80 C 60 10, 120 10, 170 80" fill="none" stroke="transparent"
        stroke-width="24" pointer-events="stroke"/>
</g>

MDN’s pointer events guidance also says to make targets large enough for the biggest expected contact area, such as a finger. Because the SVG scales with its container, check the actual on-screen size at 375 pixels wide, not the size in user units. See responsive SVG.

Wire it up with one set of listeners

Pointer events cover mouse, pen and touch with one model, and pointerType tells you which one fired. For a detail panel, listen on the <svg> once and use delegation. Handle the keyboard too: making a group focusable with tabindex does not by itself make Enter or Space activate it, so add a keydown handler.

const svg = document.querySelector("#map");
const panel = document.querySelector("#detail");

function select(region) {
  svg.querySelectorAll(".region[aria-pressed='true']")
    .forEach((el) => el.setAttribute("aria-pressed", "false"));
  region.setAttribute("aria-pressed", "true");
  panel.textContent = `${region.dataset.name}: ${region.dataset.value}`;
}

svg.addEventListener("click", (e) => {
  const region = e.target.closest(".region");
  if (region) select(region);
});

svg.addEventListener("keydown", (e) => {
  if (e.key !== "Enter" && e.key !== " ") return;
  const region = e.target.closest(".region");
  if (region) {
    e.preventDefault();
    select(region);
  }
});

Put aria-live="polite" on the #detail element so screen readers announce the new text. Because the groups now act like buttons, give them role="button" and an accessible name, and keep aria-pressed accurate. SVG accessibility covers roles and names in more detail, and SVG with JavaScript explains the event and coordinate APIs used here.

If you only want hover effects for mouse users, check event.pointerType === "mouse" in a pointerenter handler and skip the rest.

Tooltips: use HTML positioned from the shape

SVG text does not wrap and cannot easily hold rich content. A common pattern is an absolutely positioned HTML element that you place from the shape’s on-screen box:

function placeTooltip(region, tooltip) {
  const box = region.getBoundingClientRect();
  tooltip.style.left = `${box.left + box.width / 2 + window.scrollX}px`;
  tooltip.style.top = `${box.top + window.scrollY - 8}px`;
}

getBoundingClientRect() returns on-screen pixels, which is what you want for HTML. getBBox() returns user units and ignores transforms, so it suits positioning labels inside the SVG. Also hide tooltips on blur and on Escape, and do not make them the only place information lives.

Interaction without any script

SMIL can react to pointer events by itself. The begin attribute accepts event values such as elementId.click, so an animation or <set> can start when a shape is clicked. MDN’s list of supported events includes focus and keydown, but test keyboard behavior in your target browsers before depending on it.

This is useful for small, decorative reveals in an SVG that is embedded as a document. It is not a replacement for the keyboard-accessible pattern above, and SMIL timing for the content people need should not be the only path to it.

Motion and polish

Transitions on color and opacity are enough for most infographics. If shapes move, scale or sweep, honor prefers-reduced-motion, as the first example does for its transitions. SVG animation shows how to cover CSS, SMIL and script. Soft shadows or glows on hover are possible with SVG filters, but a filter on every shape in a large map can cost more than the effect is worth.

A short checklist

  • Key information is visible without hover.
  • Every interactive region can be reached with Tab and activated with Enter or Space.
  • Focus has a visible style that meets contrast requirements.
  • Hover styles are wrapped in @media (hover: hover).
  • Thin shapes have a larger hit area.
  • A text panel or table carries the same data.
  • Transitions stop under reduced motion.
  • You tested with a real phone, a keyboard alone and a screen reader.

Sources

Checked against these references on 2026-11-21.