Web platform

HTML-in-Canvas ships in Chrome 157, and the canvas finally holds real markup

HTML-in-Canvas ships in Chrome 157, and the canvas finally holds real markup

Here's a canvas in its natural habitat: ctx.fillText("Dear Santa, I would like:", 20, 40). A pile of pixels cosplaying as a paragraph. No text nodes, nothing in the accessibility tree, and Ctrl+F shrugs. Want a text input in there? Cool. Go hand-roll a caret, selection, IME support and right-to-left text. (People did this. People still do this. I need a minute.)

Natalia Markoborodova, a Developer Relations Engineer on the Chrome team, walks through the way out on day 5 of the HTMHell Advent Calendar: the HTML-in-Canvas API, which shipped in Chrome 157. Short version: you put real HTML inside <canvas> and ask the browser to paint it. The form stays a form.

Three small pieces

That's the whole surface you need to start:

  • content="drawable" on the <canvas> tells the browser to lay out its children.
  • The drawable attribute marks an element you can draw independently.
  • ctx.drawElementImage() paints that element's pixels into the canvas. In 2D it also keeps the DOM geometry in sync with where you drew it, so clicks, focus and hit testing land in the right spot.

The source's Santa letter, as-is:

<canvas id="canvas" width="600" height="400" content="drawable">
  <form id="letter" drawable>
    <h2>Dear Santa,</h2>
    <label for="wish">I would like:</label>
    <input id="wish" name="wish" autocomplete="on" value="a puppy">
    <button>Send to the North Pole</button>
  </form>
</canvas>
const ctx = canvas.getContext("2d");
canvas.onpaint = () => {
  ctx.reset();
  ctx.drawElementImage(letter, 20, 20);
};

Per Markoborodova, that <form> is in the accessibility tree. Tab moves focus into it, autofill fills it, Ctrl+F finds "puppy", translation translates it, DevTools inspects it, and CSS styles it, forced colors mode included. That's a big chunk of the browser you used to rebuild by hand, handed back.

Why both old escape routes stank

The article lays out the two options you had before. Option one: draw every control yourself and keep a second, invisible DOM around so assistive tech has something to read. Two UIs, synced forever. Option two: float real HTML over the canvas and recalculate its style.transform every frame, which jitters when the camera moves and can never sit behind a 3D object.

The built-in answer was fallback content between the <canvas> tags, and the numbers on that are grim. Chrome's public usage counters, quoted in the explainer's GitHub discussions, put <canvas> on about 45% of page loads and HTML between the tags on about 0.4%. Markoborodova is fair about it: the 45% likely includes plenty of invisible helper canvases that never need fallback. Still a gap you could park a truck in.

Wait — this is the bit that got me. The drawable attribute exists because accessibility experts pushed back in public. Drawing only direct children of <canvas> would have forced authors to flatten their markup, and per the source, a 36-comment discussion is why you can now draw any descendant and keep the semantic structure around it:

<canvas id="canvas" content="drawable">
  <figure>
    <img drawable id="puppy" src="puppy.png" alt="A small, very fluffy puppy">
    <figcaption drawable id="caption">Exhibit A: what I want for Christmas.</figcaption>
  </figure>
</canvas>

The <figure> still ties image and caption together for assistive tech, even if you paint them on two different walls of a 3D gallery. The very first explainer, from August 2024 when the API was still called placeElement, said it straight: "This API would allow developers to do the right thing." The internet starred it for the shaders. Fine. The accessibility was the point.

Going 3D

In WebGL or WebGPU the browser can't know where your texture landed, so you tell it:

canvas.updateElementGeometry(letter, { canvasTransform: matrix });

No CSS string parsing, no per-frame style recalculation, no overlay drift. A few other cursed-but-legal tricks from the source: same-origin iframes inside a drawable element get painted (cross-origin ones stay blank), showModal() on a <dialog> inside the canvas sends it to the top layer as a perfectly flat, normal dialog, and captureElementImage() gives a Web Worker a transferable snapshot to draw into an OffscreenCanvas. Canvas inside HTML inside canvas, three levels deep, is in the web-platform-tests. Of course it is.

The fine print

  • HTML-in-Canvas shipped in Chromium-based browsers. Markoborodova's advice for everything else is feature detection plus a fallback: static rendering, overlays, or a library. The API is at Stage 3 (Committed) in the WHATWG process, which means its shape is approved.
  • Undrawn content is still content. Everything inside <canvas content="drawable"> is in the accessibility tree whether you paint it or not, so hide stale panels with hidden or inert, or remove them.
  • Hit testing only follows linear transforms. Bend text around a sphere with a shader and clicks won't follow it.
  • It's main thread only for now, with no threaded animations yet.
  • Captions and video controls aren't painted, so a video run through a shader loses its captions unless you provide them some other way.
  • For privacy, cross-origin images and iframes stay blank, and so do private details like visited links.
  • Wobbly, shattering UI is fun until it makes someone sick. Respect prefers-reduced-motion.

Verdict

Canvas spent its whole life as a screenshot of a UI. Now it can hold the UI itself, and screen reader users, translation and keyboard navigation come along without a second DOM. That honestly makes me a little happy about the web in a way the shader demos alone wouldn't. Ship it behind feature detection, keep your fallback honest, and go put a form on a snowflake. Nine out of ten, with the missing point waiting on more than one engine family.

Source: HTMHell (htmhell.dev)

Related
Web platform

A pageflip demo puts the experimental HTML-in-Canvas API through its paces

A bram.us demo builds a pageflip/flipbook custom element on the experimental HTML-in-Canvas API, using it to render real DOM inside a 3D canvas effect so pages stay selectable and links stay clickable.

September 9, 2026
Accessibility & semantics

A canvas is a blank image to a screen reader until you give it HTML

On day 2 of the HTMHell Advent Calendar, Rhiana Heppenstall explains how her team added fallback HTML to canvas-based reading activities so keyboard and screen reader users can play them. The post walks through the markup, the live regions and the trade-offs the team made.

December 2, 2026
Accessibility & semantics

Chrome 150 hands composite-widget arrow keys to the browser

Chrome 150 ships the `focusgroup` HTML attribute, a way to get roving arrow-key focus inside composite widgets like listbox, tablist and toolbar without a line of JavaScript. Adrian Roselli has published script-free demos, and the spec story is still an Open-UI explainer.

July 6, 2026