Contacto
Gabs
Blog

HTML-in-Canvas is for canvas you already have

HTML-in-Canvas runs only in Chrome 157 and up. Safari and Firefox, 19% of page views, still need your current canvas as the fallback.

Gabriel EspinheiraSenior Full-Stack Engineer
  • Published
  • 9 minReading time
  • DesignCategory

Listen to this post· AI-narrated

0:00 / 10:29

Chrome's launch post for HTML-in-Canvas (opens in a new tab) shows four lines of Three.js code: wrap a form in THREE.HTMLTexture, put it on a cube, done. Run that on Chrome 157, the release that ships the API, with Three.js r187, the latest release, and the cube comes out blank. The fix is still an open pull request (opens in a new tab) planned for r188. The API works: live, accessible HTML drawn inside a 2D, WebGL or WebGPU canvas. But it runs in Chromium only, part of the ecosystem built on its trial version broke on release day, and a Mozilla engineer argues against it. My take: use it to upgrade a canvas UI you already have, and never move a working HTML page into a canvas to get it.

TL;DR: HTML-in-Canvas is on by default in Chrome 157 and draws real, selectable, screen-reader-visible HTML inside a canvas. Safari and Firefox don't support it, and they carry almost one page view in five. Use it to upgrade canvas UIs you already ship, behind feature detection, with your current rendering kept as the fallback.

What does HTML-in-Canvas fix?

HTML-in-Canvas fixes the text in scenes that already have to be a canvas. Take a WebGL product viewer with a spec card pinned to the model. Today that card is one of three compromises:

Drawn as pixels. Text painted with fillText() is crisp and in the scene, but a screen reader gets nothing, Find-in-Page can't see it, and nobody can copy the dimensions off it. Every line break and right-to-left language is your code.

HTML floated over the canvas. The text is real, but you recompute its transform in JavaScript every frame to keep it on the model, it lags when the camera whips round, and it can never go behind the product.

A DOM snapshot from html2canvas. It re-implements the browser's rendering, so some CSS comes out wrong, and the result is a picture: the button on it can't be pressed.

With the new API the card is an ordinary element inside the <canvas>, marked drawable, and you draw it onto the model like any texture. Chrome says it keeps its place in the accessibility tree, text selection, Find-in-Page, translation, autofill and DevTools. In 2D, drawElementImage() also moves the element's real position to where you drew it, so clicks land on the pixels. In WebGL and WebGPU the browser can't know where the texture ended up on your mesh, so you pass that transform to updateElementGeometry() yourself. One commenter in the Hacker News thread on the origin trial (opens in a new tab), a web game developer, put it this way: "The killer feature is input and text rendering."

Some things are never drawn, by design: images from another origin, visited-link styles, spelling underlines and autofill values the page couldn't read anyway. JavaScript can read a canvas's pixels back, so drawing them would leak them.

Which browsers run HTML-in-Canvas today?

HTML-in-Canvas runs in Chrome 157 and later, on by default, and in Edge 157. Chromium 147 to 156 have it behind chrome://flags/#canvas-draw-element, which no visitor will turn on. Firefox and Safari don't run it, and neither has announced an implementation.

The two holdouts are in different places:

Safari. On 3 August a WebKit engineer wrote on WebKit's standards-positions issue (opens in a new tab) that they "will mark this proposal as support in a week pending objections". As of 14 November the issue still carries no position label.

Firefox. Mozilla's issue (opens in a new tab) has been open since September 2024 and is still marked "needs proposed position". A Mozilla graphics engineer has argued against it in that thread, covered below.

StatCounter puts Safari at 16.59% and Firefox at 2.57% of worldwide page views in October 2026 (opens in a new tab), 19.16% together. On worldwide numbers, almost one visitor in five sees your fallback instead of whatever you build with HTML-in-Canvas, before you count Chrome users not yet on 157 and Chromium forks on older versions. Your own analytics will give you your share. For those visitors, the fallback is the product.

Does your 3D library work with HTML-in-Canvas in Chrome 157?

Check the version before you trust a tutorial. The API changed shape during its origin trial, and Chrome 157 dropped the old names: the canvas opts in with content="drawable" instead of layoutsubtree, texElementImage2D became texElementSubImage2D in WebGL, and copyElementImageToTexture became drawElementImageToTexture in WebGPU. Libraries that added support during the trial broke the day 157 shipped. Chrome's own launch post still says PixiJS "shipped built-in support in version v8.19.0", and the 8.x releases through 8.22.0 throw "texElementImage2D is not available" (opens in a new tab) on Chrome 157.

Here is where the four engines in Chrome's post stand on 14 November:

LibraryAPIWorks on Chrome 157 from
Three.jsHTMLTextureNot yet. r187 leaves the texture blank; the fix is planned for r188
PixiJSHTMLSource8.23.0 (opens in a new tab), released 11 November
PlayCanvasTexture.setSource()2.24.0 (opens in a new tab), released 9 November
Babylon.jsHtmlTexture9.33.0 (opens in a new tab), released 29 October

The Three.js failure is the dangerous kind. Its HTMLTexture only uploads when the old method exists, so on Chrome 157 it skips the upload without an error, and you find out from a blank face on a mesh in production. If you're on Three.js, call the new WebGL method yourself or wait for r188.

When should you use HTML-in-Canvas, and when not?

Use HTML-in-Canvas where you would draw a canvas anyway. A product configurator with labels on the model, a whiteboard or design editor, a game's menus and chat, a shader transition between two real pages: all of these already paid the canvas cost, and the API hands them the browser's text, input and accessibility back. In 2D you get that almost for free. In 3D you also own the geometry sync, so plan for that work before you call it done.

Don't use it to rebuild a normal page inside a canvas because you want a shader on it. A short transition between pages is a moment on top of pages that work without it; a page rebuilt inside a canvas makes the canvas the page. The case against that comes from Mozilla, and it holds whether or not Firefox ever ships the API. In the standards thread (opens in a new tab), Mozilla's graphics engineer explains that browsers can scroll and animate DOM content off the main thread, so it stays smooth when JavaScript is busy, while what a canvas shows is decided entirely by the JavaScript event loop. His conclusion: "rendering documents to a Canvas2d instead of the DOM is the wrong approach at multiple levels and as such we are opposed to encouraging web authors to go down that road."

I agree with him on pages and disagree on apps. Complexity has to earn its place. A canvas earns it when the scene needs pixels HTML can't produce, and in that case HTML-in-Canvas lowers the cost. A marketing page, a form or a dashboard earns nothing from it: you'd trade smooth scrolling and a page that works in every browser for an effect.

How do you ship HTML-in-Canvas with a fallback?

Ship HTML-in-Canvas as progressive enhancement: detect it, draw with it where it exists, and keep the rendering you already have everywhere else. Detect the attribute, not the browser or the method. Chromium builds from 147 to 156 can expose drawElementImage() behind a flag while only understanding the old layoutsubtree attribute, so a method check passes on builds where your markup does nothing. Chrome's own check (opens in a new tab) sets the new attribute and reads it back:

function supportsHtmlInCanvas() {
  const canvas = document.createElement("canvas")
  canvas.setAttribute("content", "drawable")
  return canvas.content === "drawable"
}

const canvas = document.querySelector("#scene")
const card = document.querySelector("#card")

if (supportsHtmlInCanvas()) {
  const context = canvas.getContext("2d")
  canvas.addEventListener("paint", () => {
    context.clearRect(0, 0, canvas.width, canvas.height)
    context.drawElementImage(card, 40, 40)
  })
  canvas.requestPaint()
} else {
  canvas.after(card)
}

The markup puts the element inside the canvas, with both opt-ins: <canvas id="scene" width="600" height="400" content="drawable"> around <form id="card" drawable>. The paint event fires when a drawable element changes, at most once a frame, and requestPaint() asks for the first one.

Two details decide whether this works. First, every element you draw needs its own drawable attribute. Without it, drawElementImage() throws InvalidStateError inside the paint handler, and since that handler is the only thing drawing, the first symptom you see is a blank canvas. Second, the else branch is not optional. Anything inside a <canvas> is fallback content, and a browser that can draw the canvas never renders it. In Safari and Firefox your form exists for screen readers and nobody else, until you move it out, as canvas.after(card) does here. That line is the simplest fallback, fine for a 2D card. In a 3D viewer, the else branch is where your existing overlay or fillText() code keeps running.

What to do this week

If you ship a canvas, WebGL or WebGPU interface, pick the one piece of text in it that hurts most today, usually a label or a form drawn with fillText(), and move it to HTML-in-Canvas behind the check above. Test it in Safari and Firefox before Chrome, because that's where your fallback has to carry the page. Check your 3D library's version against the table first. On Three.js, wait for r188 or upload the texture with texElementSubImage2D() yourself and pass the mesh's transform to updateElementGeometry(). If you were planning to rebuild a working HTML page inside a canvas to get a shader effect, don't.

I write about web platform changes and how to ship them on the gabs.app blog. I'm a full-stack engineer and my work is on gabs.app; if you're hiring, the contact form comes straight to me.