HTML-in-Canvas Lands in Chrome 157

Chrome 157 reached the stable channel on November 3, 2026 carrying the HTML-in-Canvas API: real DOM elements drawn inside a canvas, with hit testing and the accessibility tree still intact. What gets painted stays an element in the document, not just pixels.

The problem: canvas only paints pixels

Canvas has always been a blind drawing surface. Whatever is painted into it has no presence in the accessibility tree, receives no clicks, and cannot be focused with the keyboard. Teams building their interface inside WebGL — design editors, interactive maps, 3D product configurators — face two options, and both cost something.

The first is rebuilding every button and every input by hand inside the canvas. The result looks right and fails in practice: no screen reader reads it, no keyboard reaches it, no text selection, no respect for system preferences.

The second, far more common, is an HTML layer positioned over the canvas with CSS, plus code that syncs coordinates on every camera move. It works in 2D scenes and falls apart in 3D — the layer never occludes behind an object, never rotates with the scene, never sits at depth.

What changed in Chrome 157

The new API adds a content="drawable" attribute on the canvas and a drawable attribute on any element inside it. That element, with its whole subtree, can then be drawn into the rendering context:

  • In a 2D context, ctx.drawElementImage(el, x, y) paints the element and syncs its hit-testing and accessibility bounds automatically.
  • In WebGL, gl.texElementSubImage2D(...) copies the element into a texture.
  • In WebGPU, device.queue.drawElementImageToTexture(...) does the same.
  • For those last two, canvas.updateElementGeometry(el, { canvasTransform }) maps the element's DOM position to where it was drawn, and clearElementGeometry(el) removes it from hit testing.

The substantive difference is that the element stays in the document. A button drawn inside a 3D scene is still a button: the screen reader announces it, the keyboard reaches it, and the text inside it honors user preferences.

A practical example

html
<canvas id="viewport" content="drawable" width="800" height="400">
  <div id="toolbar" drawable>
    <button type="button">Export</button>
    <input type="range" min="0" max="100" />
  </div>
</canvas>
js
const canvas = document.getElementById("viewport");
const ctx = canvas.getContext("2d");
const toolbar = document.getElementById("toolbar");

canvas.onpaint = () => {
  ctx.reset();
  drawScene(ctx);                        // your own rendering
  ctx.drawElementImage(toolbar, 24, 24); // the DOM subtree, painted
};

canvas.requestPaint();

The paint event is the control point: request it with requestPaint(), and redraw inside onpaint. Before any of that comes the support check:

js
if (!("content" in HTMLCanvasElement.prototype)) {
  // fall back to a CSS-positioned HTML overlay
}

Real-world caveats

  • Chrome only, so far. The feature ships behind the CanvasDrawElement flag, marked stable in M157. Firefox and Safari have not shipped it, so the fallback path is not optional.
  • No cross-origin content. Content from another origin is unsupported inside the canvas.
  • Hit testing is not automatic everywhere. In a 2D context, only elements drawn with drawElementImage() or registered through updateElementGeometry() are hit-tested. The WebGL and WebGPU paths need updateElementGeometry() explicitly, or the clickable region drifts away from the visible image.
  • Texture sizing. In WebGL, use mutable storage via texImage2D(..., null) rather than texStorage2D. In WebGPU, textures cannot be resized: recreate the texture and rebuild any bind groups when the element's size changes, and pass size to drawElementImageToTexture or a larger element gets clipped.
  • Do not create a `ResizeObserver` inside `onpaint` — a known path to leaked memory.
  • `captureElementImage()` throws if the element has no paint record yet; call requestPaint() and retry.

One more thing worth holding onto: Chrome now ships every two weeks, so reaching stable no longer means reaching users. Revisit what the two-week cycle changes before building assumptions on a version number.

Takeaway

HTML-in-Canvas does not make canvas faster. It ends the trade-off between custom rendering and accessibility. Teams that used to choose between an interface that looks right and one that can actually be used can now build both from a single source — as long as the fallback path stays in place until the other browsers catch up.

Primary source: Expose canvas content to browser features — Chrome for Developers and the Chrome 157 release notes.