NewsCrawler.org

Accessible UI with HTML-in-Canvas: buttons and headings drawn on a canvas

HTML-in-Canvasで作るアクセシブルなUI
オリオン座の7つの星が金色の線でつながり、「星座線を表示」ボタンの周りに白いフォーカス枠がある
Image: zenn.dev

HTML-in-Canvas[1] is an API for drawing HTML elements, such as buttons and headings, onto a Canvas. If you draw only shapes and text on a Canvas, keyboard users cannot reach a button with the Tab key, and a screen reader[2] does not announce it as a button. According to the article, the original HTML stays available after drawing, so headings are read aloud and buttons can be reached with Tab. Before this API, developers had to build a separate HTML layer for screen readers and keep two versions in sync; with HTML-in-Canvas, one HTML structure covers both.

The article builds a demo called "Small Planetarium" that shows and hides lines joining the seven stars of Orion. The stars and lines are drawn on a Canvas, while the explanation and the toggle button stay in HTML. The drawing runs in a paint event using drawElementImage(), and the button's aria-pressed[3] value switches each time the button is pressed. As of 24 November 2026, the API works in Chrome 157, and the article says some browsers do not support it yet, so it also covers a fallback for them.

For screen reader users, aria-pressed reports whether the lines are shown, and a live status line with role="status" announces the result, for example that the seven stars are connected. Visually, a gold background shows the pressed state, and a white focus ring marks the keyboard position.

Read the original zenn.dev

Sources

  • Zenn JA

    HTML-in-Canvasで作るアクセシブルなUI

    14 likes1 bookmark0 comments

Published: First seen: Читать по-русски

Open as a page