Accessibility audit of DOM drawn in a canvas
The claim for HTML-in-canvas is that the pixels are still elements, so they can be focused, searched and selected and they're in the accessibility tree. I wanted to check that, so this page tests it four ways: probes of the API, a table of the patterns used on this site, the same audit run over every page here, and a short list that only a person can do.
A · What the API gives you probes on small fixtures
Show the code how a probe is set up
Once the probes have run, every row has its own Show the code link with the exact function it ran.
rig(): a drawable canvas, some children, and a draw function called on everypaint. This is the smallest complete HTML-in-canvas set-up: thecontent="drawable"andlayoutsubtreeattributes on the canvas,drawableon each child, anddrawElementImage()in the paint handler.- The thirteen patterns of section B. One page that builds the same card each way.
- The audit itself.
auditDocument(doc)runs on any same-origin page.
B · Pattern by pattern the same card, put in a canvas thirteen ways
Each row builds one small card (heading, a sentence, a text field, a button, a link) into a canvas a different way, then measures five things: focus, selection, find, zoom and forced colours. The last column was recorded from outside the browser with the DevTools protocol, which can read the real accessibility tree and press a real Tab key. Select a cell for the detail.
C · Every demo, audited runs in the frame below
The demo list is read from the shared menu (/shared/pages.js, built from each page's page.json), so a new demo is audited as soon as it has a page file.
To audit any other same-origin page, enter its path. Select a cell for the detail.
The first two columns are about behaving on a phone: has the page scrolled, taken focus or jumped about by the time its own checks finish, and is every canvas showing a picture. /a11y/?url=/slot/ checks one page straight away.
✓ holds up! works with a caveat✗ broken for some users– nothing to test
D · Needs a person about ten minutes
None of these can be scripted from a page. The panel is drawn tilted and offset on purpose, so anything positioned from stale geometry shows up in the wrong place. Your verdicts are kept in this browser and included in "Copy results".
E · Checked with the DevTools protocol Chromium 157 headless, 2026-11-20
A page can't ask these things about itself, so they were driven from outside the browser while the audit was built.
| ✓ works | Accessibility tree Accessibility.getFullAXTree on a canvas with a labelled input, button and link. | The canvas is a "Canvas" node and its children are ordinary nodes under it: textbox "Name", button "Press me", link, StaticText. Roles and names are the same as outside a canvas. |
| ✓ works | Real Tab key Input.dispatchKeyEvent Tab, six times. | Focus walks the canvas children in DOM order. Each focus change fires a paint event with the right changedElements. |
| ✗ fails | Undrawn element in the tree A drawable child the paint handler never draws. | Still a focusable button in the accessibility tree, still a Tab stop, reported at the canvas origin (its static layout position) rather than without geometry. A sighted keyboard user lands on nothing. |
| ✓ works | Real mouse Click, double-click, drag and shift-click at the drawn position. | Clicks reach the element, a click in a text field puts the caret there, drag selects text. |
| ✓ works | IME composition Input.imeSetComposition "にほん", then commit "日本". | compositionstart, update and end fire; the composing text is painted into the canvas and the committed value is right. Where the candidate window opens needs a real IME. |
| ✓ works | Forced colours Emulation of forced-colors: active. | The drawn element is repainted in system colours (its yellow background becomes Canvas). The explainer lists forced colours as not sensitive, and this build paints them. |
| ✓ works | System colours and colour scheme Canvas, CanvasText, AccentColor, light-dark() inside a drawn element. | All painted with their real values. (The explainer says system colours may be left out; this build doesn't leave them out.) |
| ! caveat | Zoom CSS zoom 2 on the page. | Layout and hit testing follow, but a canvas with a fixed width attribute keeps its bitmap and is stretched. A canvas has to resize itself (ResizeObserver with device-pixel-content-box) to stay sharp. |
Findings
- The claim holds for elements that are drawn. Elements drawn with
drawElementImagekeep their role, name, focus, caret, selection, find-in-page match and forced-colours rendering, at the place they are drawn, including when rotated or drawn by a worker. - An element you don't draw is still there. Every drawable child stays in the tab order and the accessibility tree whether or not the paint handler draws it. Demos that keep spare elements in the canvas create invisible tab stops. The fix is one attribute (
inert), and you have to add it yourself. - WebGL breaks the link between pixels and elements until the author calls
updateElementGeometry: the texture is on screen but focus rings, hit testing and screen magnifier tracking still point at the element's layout position. - Pixels sent out of the canvas have no accessibility information. Mirrors, other tabs and other origins receive bitmaps. Those canvases need their own label or a link back to the live element.
- The patterns only differ under zoom. Slots, a shadow root on body, a worker, a WebGL texture: the accessibility tree, Tab order, find and selection come out the same in all of them. Patterns that position the element with their own transform fall out of step with the CSS
zoomproperty. - Always pass a size to
drawElementImage. Without one it draws in device pixels, so afterctx.scale(devicePixelRatio)the element is too big on every HiDPI screen. A canvas sized fromdevicePixelContentBoxSizehides this under DevTools device emulation, where that box stays in CSS pixels. - The page has to handle zoom. Nothing draws a canvas again when the page is zoomed.
<canvas-slot>does it with a device-pixel ResizeObserver. Most of the canvases I wrote by hand don't.