hn.today

HTML-in-Canvas: Draw live DOM subtrees directly into 2D, WebGL, or WebGPU canvas

developer.chrome.com3 points0 comments
Screenshot of HTML-in-Canvas: Draw live DOM subtrees directly into 2D, WebGL, or WebGPU canvas

HTML-in-Canvas lets developers render live DOM subtrees inside 2D, WebGL, or WebGPU canvases. It combines the styling and interactive, accessible content of HTML with the visual control and rendering capabilities of canvas, while retaining browser features such as accessibility trees and browser-level integrations. The API is suited to interfaces that need to appear within canvas-based scenes or effects without rebuilding their content from scratch using canvas drawing commands. Its implementation varies by rendering context, and developers need to understand shared concepts such as drawable content and paint events before connecting an element to a canvas and keeping its geometry in sync.

Developers can use browser APIs directly or adopt libraries with experimental or shipped support. Examples include Three.js, Babylon.js, and PlayCanvas for using HTML as a texture in a 3D scene, and PixiJS for turning an HTML element into a sprite and synchronizing its transform. These integrations can reduce the manual work involved in updating textures and positioning elements, but their availability and maturity differ; the listed libraries are community projects, not officially supported by Google or Chrome. The guidance also points developers to separate instructions for each canvas type, fallback strategies, framework support, and community demos, and recommends Modern Web Guidance for coding-agent-assisted implementation.

Read on developer.chrome.com0 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Web

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.