Video, image and chart tiles

Five media ideas from the element catalogue: a <video> drawn as a wall of tiles, a <figure> whose image goes through an effect while its caption does not, a <picture> whose file is chosen by the size the canvas draws it at, an SVG chart drawn turned and tilted with its hover styles and links working, and a script-drawn chart exported with its HTML legend as one PNG. I wanted to know whether each media element keeps its own behaviour (controls, srcset, :hover, links, checkboxes) when a canvas draws it in pieces, at another size or under a transform.

Video wall

One <video controls> element, drawn as a grid of tiles that drift apart. Move a pointer over the wall or tap it: the tiles close up, and the video's own controls can be used. Four seconds after the last touch the tiles drift again.

Every tile is a source rectangle of the same element, drawn in the same paint handler, so all tiles hold the same video frame. Each such draw moves the video's hit region to that tile. A last draw of the whole video inside an empty clip puts the region back on the closed wall, which is where the controls answer.

Show the code
  1. Draw one video as tiles, each with its own transform.
  2. Close the wall while it's used.
  3. Styles.

Figure with a live caption

A <figure> with an <img> and a <figcaption>. The buttons choose what the canvas does to the image. The caption is drawn on top with no effect: its words can be selected and edited, and its link can be followed.

A drawn sunset: a sun over five ranges of hills and a lake
Sunset over the lake. Image file

The figure itself isn't drawn. Its two children carry the drawable attribute, so each has its own picture and its own hit region. The dark panel behind the caption is a third draw of the image, clipped to the caption's box and blurred with ctx.filter.

Show the code
  1. A figure whose image and caption are each drawable.
  2. Four effects on the image, then the caption with one plain draw.
  3. Styles.

Resolution chosen by drawn size

A <picture> with four files, 160 to 1280 pixels wide. Each file has its width written in its top left corner. Move the slider or walk up to the picture: the page writes the drawn width into sizes, and the browser picks the file. The loupe in the corner enlarges the part round the sun, from the same element.

The same drawn sunset, with the width of the file in its corner

The image is laid out at 160 CSS pixels and is never laid out again. Only sizes changes. The browser goes up through the files as the picture grows and keeps the largest one when it shrinks again. With the box unticked, sizes is written once when the walk ends, and only one file is fetched for it.

Show the code
  1. A <picture> with width descriptors.
  2. Write the drawn width into sizes and draw the image at that width.
  3. List the files that were fetched.
  4. New URLs, to watch the choice from the start.
  5. Styles.

SVG chart as a live texture

An inline <svg> bar chart, drawn as a thick sheet that sways. Each bar is a link with a hover style. Point at a bar with a mouse, or tap one: the bar changes colour through its own CSS, and the canvas adds a label that it reads from the chart. Drag sideways to turn the sheet.

Visits by day 42 68 55 90 73 31 MonTueWedThuFriSat

A 2D context has affine transforms only, so the sheet is drawn in an orthographic view: a turn, then a squash. That's one matrix, and drawElementImage() gives the same matrix to the hit region. A perspective view would need a mesh of triangles, and the hit region would then follow only the last triangle.

Show the code
  1. The chart: bars are <a> elements around a <rect>.
  2. Draw the chart turned and tilted, and read :hover in the paint handler.
  3. A tap follows the bar's link.
  4. Styles: hover, the bar transition and the animated line.

Chart and legend exported as one picture

A ring chart drawn by script into a plain <canvas>, beside an HTML legend of checkboxes, in one <figure>. Untick a row to remove its slice. The outer canvas draws the figure, and one toBlob() call on it gives the chart, the legend and the caption as a PNG.

Visits by source, one week. Untick a source to leave it out.

The inner canvas isn't a drawable canvas. It's content of the figure, like an image, and it is in the figure's picture. The export reads the outer canvas once, on the tap. The picture under the buttons is the exported file.

Show the code
  1. A figure with a plain canvas, a list of checkboxes and a caption.
  2. Draw the ring into the inner canvas.
  3. Draw the figure in the outer canvas and export it with one call.
  4. Save, copy and share the PNG.
  5. Styles.

How it works

Each demo is one 2D drawable canvas with one media element in it. The paint handler draws the element with drawElementImage(), and reads what it needs from the element at that moment.

Show the code
  1. The paint loop and the draw helpers shared by the five demos.
  2. Each demo starts when its section comes near the screen.
  3. A lost context stops every demo.
  4. The elements are then shown as plain HTML.

Live checks

The checks wait for a tap. Each one builds its own small canvas in a corner of the window, and none of them touches the demos above. Pixels are read from a drawImage() copy, not from the drawable canvas.

Findings

Measured in headless Chromium 157 on 2026-11-21, at 412 px wide with a mouse and emulated touch, at device pixel ratio 1 and 2.625. Not yet run on a phone.