What happens when the DOM can go anywhere a pixel can?
Experiments with the HTML-in-canvas API: reprojecting real, interactive DOM through slots, workers, tabs and origins. Each page runs live tests in your browser and says what works and what doesn't.
The building block
canvas-slot.js is one dependency-free module. Children with a slot name are projected into a
canvas; you get a render callback with a draw(name, x, y) helper. Add worker="…" to render off the main thread, or pair it with
slot-share.js to publish slots to other tabs and origins.
<script type="module" src="https://html-in-canvas-demos.kinlan-test.workers.dev/lib/canvas-slot.js"></script>
<canvas-slot id="stage">
<h2 slot="title">Real DOM</h2>
<button slot="cta">Still clickable</button>
</canvas-slot>
<script type="module">
const stage = document.getElementById('stage'); // the <canvas-slot> element
// draw(slotName, x, y) is drawElementImage() for the element in that slot.
stage.onrender = ({ ctx, draw, time }) => {
ctx.rotate(Math.sin(time / 800) * 0.05);
draw('title', 20, 20);
draw('cta', 20, 90);
};
</script>
Where this could go
- A drop-in element with named effects.
<canvas-slot effect="tilt">so nobody writes a render loop: ship a small set of effects (tilt, ripple, dissolve, page-curl) and let CSS custom properties drive them. - Shader slots. The same element with a WebGL/WebGPU backend: each slot becomes a texture and
effectpoints at a fragment shader. "CSS filters you can write yourself." - View transitions you own. Capture the outgoing and incoming DOM as two slots and blend them in a shader, while both stay live.
- DOM in 3D. three.js
HTMLTexturescenes where panels are real forms, withupdateElementGeometrykeeping hit testing right. - Accessibility audit. What the accessibility tree, focus order, find-in-page, selection and zoom look like for slotted content, per pattern.
- Portable widgets. A
<slot-view>protocol for embedding a live piece of another site without an iframe's layout box, with consent and input forwarding. - Picture-in-picture for any element. Stream a slot into a Document PiP window or a
<video>viacaptureStream(). - Export. Record DOM animations straight to video with WebCodecs, or print-quality PNGs of any component.
Needs Chrome 148+ with chrome://flags/#canvas-draw-element (or the html-in-canvas origin trial). Everything else, including this page, is plain HTML.
Source: github.com/PaulKinlan/html-in-canvas-demos.