Skip to main content
ExodeUI

EXODEUI DESKTOP

A little space for good ideas.

Choose your platform to get the official ExodeUI installer.

Looking for Intel Mac or other builds? Explore the web studio or check all download options.

Prefer the browser? Try for free in your browser →
Engineering1 min read·Updated November 2026·By the ExodeUI team

Hit Testing in Canvas UI: Making Animated Graphics Clickable and Accessible

How clicks and taps work on canvas-rendered animations: hit testing, pointer events, touch target size, and keeping canvas UI accessible with real controls.

Direct Summary & Definition

Core Takeaway

A canvas is one bitmap, so the browser cannot tell which drawn shape you clicked. Hit testing is how your code or animation runtime works that out, by checking the pointer position against shapes or invisible hit areas. Use pointer events for mouse, touch and pen together, make hit areas at least as large as accessibility guidelines suggest, and pair canvas graphics with real HTML controls for keyboards and screen readers.

Why canvas needs hit testing

With HTML, every button is an element that receives its own events. On a canvas, everything is pixels, so you get one event for the whole canvas with an x and y position. The Canvas API offers isPointInPath and isPointInStroke to test a point against a path. Animation runtimes do the same internally for their listeners and state machine inputs.

Pointer events for every input

Pointer events unify mouse, touch and pen. Listen for pointerdown, pointermove and pointerup on the canvas, convert the position into the canvas's coordinate space (accounting for CSS size, device pixel ratio and any scaling of the artwork), and then test it.

  • Use pointer capture so a drag keeps working when the pointer leaves the shape
  • Set touch-action in CSS so the browser does not scroll during drags
  • Handle pointercancel, which fires when the system takes over a gesture

Hit areas larger than the art

A tiny drawn icon is hard to tap. WCAG 2.2 sets a minimum target size of 24 by 24 CSS pixels with some exceptions, and platform guidelines recommend larger targets on touch screens. Use invisible hit shapes that are bigger than the visible artwork, especially for small controls.

Keep it accessible

Screen readers and keyboards cannot see shapes inside a canvas. Put real buttons, inputs and labels in the HTML, either visibly next to the canvas or positioned over it, and let them drive the animation's inputs. The canvas then shows the motion while the HTML carries meaning and focus.

Building this in ExodeUI

ExodeUI, which we make, handles pointer input on its canvas for you, and its components expose inputs and events. The pattern we recommend: a real HTML button or input that sets the component's input, so keyboard and screen reader users get the same result as people who click the graphic.

Key Principles to Remember

  • Canvas needs hit testing because it is one bitmap
  • Use pointer events and convert to canvas coordinates
  • Make hit areas at least 24 by 24 CSS pixels, larger for touch
  • Pair canvas graphics with real HTML controls

Frequently Asked Questions

Sources

  1. CanvasRenderingContext2D.isPointInPath() — MDN Web Docs
  2. Pointer events — MDN Web Docs
  3. Understanding SC 2.5.8: Target Size (Minimum) — W3C WAI

Related Guides & Examples

Canvas paired with real controls

See how our component pages pair each canvas animation with an accessible control.

Open the toggle
Try for free