Skip to content

HTML-in-Canvas is stable in Chrome 157. Little code, mostly where to use it, with public demos and a video in the post and a look at how the studio hero uses it.

Published 1 view

HTML-in-Canvas is a stable feature in Chrome 157. The Chrome developer blog announced the stable release on October 26. In one line, it lets you draw real HTML (inputs, buttons, text) inside a <canvas>. After it is drawn, the element can still be clicked, still takes typing and stays in the accessibility tree.

Until now, putting UI in a canvas meant drawing the inputs and text by hand, or turning HTML into one flat image. A flat UI did not respond to clicks and screen readers could not read it. This feature fixes both.

You only need this much of the technique.

Source codehtml
<canvas id="c" content="drawable">
  <form id="card" drawable> ... </form>
</canvas>
Source codejs
ctx.drawElementImage(card, x, y); // draw the element on the canvas

Put content="drawable" on the canvas and drawable on the element, then draw it with drawElementImage(). In 2D the element's position and pixels stay in sync on their own. In WebGL and WebGPU you tell the browser the position yourself with updateElementGeometry(). The rest is in the demos and the tips below.

The official post and the demos group the uses into six. If you already use a canvas or 3D, these are the first candidates.

Six places to use it

Six places to use it
Shader effects on UIDraw the real UI, then add glass, ripples or transitionsLiquid DOM, Compiz Web, Jelly slider
Menus inside 3D and gamesKeep a terminal, a book or a form in a 3D scene as real DOMHTML cloth, Quest Signal
Chart labelsLay out multi-line labels and legends in HTML and put them on the chartWICG pie chart
Image and video exportExport HTML-styled text with shader effects as an image or video streamThe media editing case in the official post
Text on shapesKeep text selectable and readable on a curved or warped surfaceCurved Markup
Accessible canvas appsKeep a canvas app's buttons and inputs as DOM instead of rebuilding themThe large canvas app case in the official post

Sources: the Chrome blog, the WICG repository and the Chrome team's list of community demos.

Three.js (THREE.HTMLTexture, experimental), PlayCanvas, PixiJS (built in since v8.19.0) and Babylon.js have added support, and CanvasUI is an open-source component set. Google does not maintain these libraries.

1. Detect it and keep a fallback. Support today means Chrome 157 or later. The detection in the official docs sets content="drawable" on a canvas and checks that the value reads back. When it is missing, the docs suggest an alternative UI, floating HTML or a library such as html2canvas.

2. Without support, what is inside the canvas does not show. This is something we checked ourselves. Elements placed inside a canvas are not displayed in a browser without the feature. We had to write a separate path that shows the same card outside the canvas.

3. Ask for a repaint every frame to animate. When the DOM changes, the canvas fires a paint event. For animation without DOM changes, call requestPaint() each frame. DOM changes made inside paint appear in the next frame.

4. Keep size and position in step. Size the canvas to the screen's real pixels (with a ResizeObserver) and change its size only when needed, because that clears the canvas. In WebGL and WebGPU, report an element's position every time it moves, or taps land where it used to be.

5. Hide it when decorative, keep it when it is a control. Drawn content stays in the accessibility tree like normal DOM. If it is decoration, hide it with aria-hidden and inert. If people must operate it, leave it as it is.

6. Trust what the browser protects, and know the limits. According to the WICG explainer, things that could leak, such as visited links, cross-origin content and spelling markers, are not drawn. The official post also says browser extensions can act on the drawn content, for example by changing text.

The hero on our company page draws the logo like a scribble and then introduces dsui components one by one on a canvas. Until now the cards for the button, switch, slider and others were drawn one canvas command at a time. So when a component's look changed, the hero's picture had to be fixed separately.

Now, in browsers that support the feature, six cards (Button, Switch, Slider, Tabs, Input and Chip) are drawn as real components. Without support, the old hand-drawn cards are used. The detection and the drawing live in one file, and if a draw is not possible, only that frame falls back to the hand-drawn card.

Source codets
// apps/studio/lib/home/html-in-canvas.ts
export function drawElementCentered(context, element): boolean {
  const draw = context.drawElementImage;
  if (!draw || !element.offsetWidth) return false;
  try { draw.call(context, element, -element.offsetWidth / 2, -element.offsetHeight / 2); return true; }
  catch { return false; }
}

Some things are still unchecked. We have not opened it in the stable Chrome 157 or on mobile, and we have not captured how the Tabs, Input and Chip cards look. The components inside the canvas are decoration, so they cannot be pressed.

HTML-in-Canvas fits first in screens that already use a canvas: games, 3D scenes, shader effects and editors, where you need real inputs and text that still move on top of an image. Bringing in a canvas only to add effects to ordinary web cards and buttons is still early.

The official post does not say how other browsers stand, so if you use it now, write the fallback first. Core features should work the same without it, and this should be a layer on top. Starting with decoration that the screen can do without, as in our hero, keeps the risk small.

The explanation follows the Chrome official blog and docs and the WICG explainer. We opened the demos in Chrome 156 with the feature flag on, and two that need motion (Compiz Web and Curved Markup) showed no picture in this setup, so they are not pictured. For Wes Bos's posts on X and the Quest Signal case, we only carried over what the Chrome team's list says and did not open them. We could not confirm other browsers' support because the official post does not state it.