HTML-in-canvas experiments

· HTML-in-canvas experiments

9 min read Original article ↗

What happens when the DOM can go anywhere a pixel can?

Experiments and drop-in libraries built on the HTML-in-canvas API. A <canvas> draws live child elements in 2D, WebGL or WebGPU while they keep taking clicks, typing, text selection and accessibility.

Chrome 157+ ships HTML-in-canvas on desktop and Android (this site also sends an Origin Trial token for Chrome 148 to 156; how to check or enable it). Without it, every page here shows as plain HTML. Started as a <slot> experiment by Paul Kinlan: read the story.

Examples

Thirty-one highlights of what HTML-in-canvas can do. In every picture, the UI is live HTML drawn by a canvas and you can interact with it.

A purple-to-blue ferry booking card whose text input is skinned in refracting glass

Per-element themes

Twenty-nine skins (glass, stained glass, clay, thermal, LED board, comic, X-ray, oscilloscope) wrapped round each element of a live form.

A web page with its top-right corner peeled back like paper

Peel this page back to read its HTML

One canvas draws the whole page. Drag the turned top-right corner and the page rolls back like paper to reveal the HTML the server sent.

A vertical conveyor belt between steel rollers carrying live list rows with checkboxes and Open buttons

Conveyor belt virtualised list

An endless list built from ten live DOM rows, drawn round two 3D rollers with checkboxes and buttons that still work as they roll by.

A tide table article with a rainbow-ringed lens over the text showing English to French

A lens that translates

Drag a live lens over an article to translate, simplify or summarise only the words under it while editing the original text keeps working.

Four cards drawn with ripple, glass, heat haze and CRT shaders, each containing form controls

Fragment shaders on elements

fx="ripple" draws an element through a fragment shader. CSS custom properties set the uniforms, and you can supply your own GLSL or WGSL.

Round lenses magnifying small print on a page

A magnifier over live DOM

Fifteen lenses. The area under the lens is drawn again at the lens zoom, so 4px text stays sharp, and clicks and typing pass through.

Forms drawn on jelly, hanging cloth and taped paper

Forms on a simulated mesh

Forms drawn on jelly, cloth and paper meshes. Hit testing follows the mesh, so a click reaches the control under the pointer.

Five live radio buttons arranged round a rotary dial pointing at Low

Form controls drawn as instruments

Real radio buttons arranged round a rotary dial, faders and gauges drawn by a canvas while keeping keyboard navigation and form values.

A native range input drawn in curved slices round an arc with 30 in the centre

Curved range sliders and input pickers

Five more input pickers, starting with a real <input type="range"> drawn in 3px slices round an arc with a live <output> in the middle.

Skewed form inputs connected by red and green callout lines to live validation labels

Form controls in a drawn setting

Skewed inputs and checkboxes wired to drawn callout lines that update live from the browser's own constraint validation state.

Six dark cards warped with wave, chromatic split, burning holes and CRT shaders driven by CSS rules shown on each card

Shader uniforms written in CSS only

Twelve cards drawn through one shader whose uniforms come from CSS keyframes, typed attr(), random() and if(). Edit any card's CSS live.

A select's picker drawn as a 3D carousel of theme cards with reflections

A select whose picker is drawn by a canvas

The options of a customisable <select> are drawn as a wheel, fisheye list, radial menu, 3D carousel, hand of cards or helix while keeping the value and keyboard.

A clock face picker for a time input, with hour buttons in two rings and a hand pointing at 9

Date, time and colour pickers in a canvas

A clock, a calendar and a ring of swatches replace the built-in pickers of three ordinary inputs. Every hour and day is a real button.

A text input with its datalist suggestions drawn as pills, one of them highlighted

A datalist drawn by a canvas

The <datalist> of a text input is moved into a canvas in a popover. Its options draw as a list or pills and rearrange as you type.

A dark split-flap clock showing 12:17:11 and the date beneath it

Flip clock from a time element

One <time> element whose digits flip from a snapshot of the old text to the new text, driven by paint events with no frame loop.

Four stacked details panels with Storage open showing a progress bar and Free up space button

Accordion from <details> that unfolds

Four <details name> elements joined by a paper fold, drawn as sheared strips from a snapshot when closing and live when opening.

A dashboard part way through a burn transition to another screen

Transitions between two live states

Shatter, fold and burn transitions drawn in WebGPU or WebGL. Both states accept input during the transition, and it can be held part way.

A paragraph with its letters scattered across the canvas

Text drawn glyph by glyph

Each letter of a paragraph is a particle. The paragraph stays one element, so selection, find-in-page, links and editing keep working.

A laptop in a 3D scene with a web form on its screen

A form in a three.js scene

A form used as a texture on a laptop screen, a billboard and a curved wall. Typing, Tab and text selection work on all three.

Floating panels and a keyboard in a dark virtual room

HTML panels in WebXR

HTML panels in a three.js XR scene. Controller rays become pointer events on the elements. Includes a desktop preview and a headset emulator.

A board of small documents: a to-do list, a spreadsheet, a sketch pad

A zoomable board of documents

Each tile is an element or a same-origin iframe drawn under a zoom transform. Text is rasterised again at each zoom level, up to 800%.

A dark Rust egui window floating over a sign-up form with live DOM email, select, date and textarea fields

DOM elements inside Rust egui and Qt Quick

Real HTML inputs, selects and spellcheck textareas hosted inside WebAssembly egui and Qt Quick canvases, with working window occlusion.

A dark cassette deck with spinning reels, glowing green counter and tactile rewind, play, mute and forward buttons

Cassette deck from audio controls

A tactile cassette deck with spinning reels and a glowing counter built out of real audio controls drawn into one canvas.

A video frame with a LIVE badge, a caption bar with a name, a poll with two buttons and a ticker

HTML overlays on video

A caption bar, a poll and a ticker in HTML over a video, in one canvas. Record it with sound, export frame by frame, or send it over WebRTC.

Draggable cards above a timeline slider with replay buttons

Record and replay DOM frames

A ring buffer of frames of an element. Drag the slider to scrub earlier frames, replay the last five seconds, or restore an earlier form state.

A music control panel beside a QR code that opens the same panel on a phone

One element streamed to a phone

Scan a code and one panel of the page is on your phone over WebRTC. Taps and typing on the phone are sent back and applied to the element.

A timer, a notes box and a mixer, each with a Tear off button

Widgets moved into another window

Pull a widget into a popup, an always-on-top window, another tab or another origin. What you do there happens to the element on this page.

Six elements, a timer, a form, a table, a button, a clock and a paragraph, each with a Float button

Picture-in-picture for any element

pipElement(el) puts an element in a window above your other windows: moved there, as a live picture that takes input, or as a video.

An energy account page with usage, payment and preferences panels

Share one panel of a page

Send one panel to a support agent or a vision model instead of your whole screen. Private fields are blacked out before the frame is sent.

A blog post containing a price and product card from a shop, with a permission prompt

Cross-origin widgets without an iframe box

A price and a product card from another origin, laid out inline in a blog post. The other origin asks the reader before it sends any pixels.

A support ticket card with buttons to export it as PNG, video or print

Export an element as PNG or video

captureElement(el) wraps an element in a canvas for one frame and returns a PNG. The same library records video and prints at 300 DPI.

Drop-in libraries

Several experiments grew into standalone, zero-dependency ES modules and custom elements you can import straight from /lib/ (served with CORS enabled, Apache 2.0).

fx="ripple" · /lib/fx.js

Shader CSS (single-file bundle)

Draws any HTML element through a WebGPU or WebGL fragment shader driven by CSS custom properties. Add your own GLSL or WGSL with defineEffect().

<canvas-slot> · /lib/canvas-slot.js

Slots inside a canvas

The custom element that started this site: project light-DOM children into a canvas with draw(name, x, y), shader effects or an OffscreenCanvas worker.

<dom-lens> · /lib/dom-lens.js

Live DOM lenses

Wrap any markup in a magnifier, glass, fisheye, thermal or X-ray lens. Sharp text re-rasterised at lens zoom, with clicks and typing passing through.

<physical-ui> · /lib/physical-ui.js

Physical UI meshes

Draw live forms on simulated jelly, hanging cloth or taped paper meshes while keeping hit testing synced with the deformed surface.

picker="wheel" · select / input pickers

Canvas form pickers

Wheel, carousel, helix, clock, calendar, swatch ring and pill pickers for real <select>, <datalist> and date/time/colour inputs.

<live-transition> · <dom-rewind> · <glyph-field>

Transitions, rewind and glyphs

Shader transitions between two live states, a ring buffer of recorded DOM frames, and interactive per-glyph text particles.

<dom-portal> · <selection-fx> · <effect-frame>

Portals, selections and frames

Mirror any live element elsewhere on the page, draw custom canvas text-selection highlights, or wrap forms in 2D canvas effects.

capture · pip · live-surface

Capture, PiP and remote DOM

Export any element to PNG, 300 DPI print or WebCodecs video, float it in Picture-in-Picture, or stream it to another device over WebRTC.

Quick start with <canvas-slot> one module, no dependencies
<script type="module" src="https://html-in-canvas.page/lib/canvas-slot.js"></script>

<canvas-slot id="stage">
  <h2 slot="title">A heading</h2>
  <button slot="cta">A button you can press</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>

Every experiment asks one question about the API, shows its running code, runs live checks in your browser and lists what worked and what didn't. Pick a topic or type to filter all 140+ pages.

I'm still adding pages as I think of ideas. The RSS feed has an entry for each one, with its question, how it works and its findings.

Learn the API

The tutorial is the one page written to teach the API from scratch: how to check support, a 60-line page that draws one element, common errors and a glossary. To see one API call in use, open an experiment from this table and read its code listing.

CallWhat it doesUsed in
drawElementImage()Draw an element with a 2D context.Start here

Limits of the API

I kept running into the same four limits, and most of the code on this site is shaped by them. The tests behind each one are in FINDINGS.md, the friction log and the crash list.

  • The element has to be a descendant of the canvas. There's no way to draw an element by reference. The slot pages use a shadow root to get round this.
  • An element has one hit-test region. If it's drawn twice, or in pieces, only one position receives input. The portal, lens and transition pages move the region to the pointer.
  • An ElementImage draws only into its source canvas. To show an element in another document, the pages send pixels and forward input events back.
  • An element that isn't drawn can still take focus. Tab reaches controls you can't see unless the page marks them inert.

About this site · Tutorial · Drop-in libraries · Friction log · RSS feed · Source on GitHub (Apache 2.0)