Form effects driven by the paint event

Five form ideas from the element catalogue. In each one the effect has no listener on the control. A key press, a pressed button, a new colour, a new progress value or a focus ring changes the control's picture, the browser raises paint on the canvas, and the paint handler reads the control's state (value, :active, position, :focus) and draws the effect from it. I wanted to know how far that goes before a listener is needed. It went all the way for four of the five. The pressed button needed a listener for touch.

Per-keystroke ink

A <textarea>. Tap it and type. Each new letter arrives wet: the canvas draws the textarea a second time, blurred and enlarged, in a circle at the letter, and a stain spreads and dries.

The wet letter is the textarea's own picture, drawn again through a blur filter. The place of the letter comes from a range over the textarea's value. Deleting makes no ink, because the handler only acts when the value got longer.

Show the code
  1. Compare the value's length in the paint handler and draw the ink.
  2. Styles.

Button press that dents the surface

A keypad of real buttons. Press and hold one: the panel sinks round it. Let go, and a ring travels out across the other keys. Space or Enter on a focused key does the same. The line under the canvas counts which route reported each press.

While the surface moves, the panel is drawn as a mesh of 144 triangles, each a clipped draw of the same element with its own affine transform. The keys are still the buttons: a draw that is clipped away at the end puts the hit region back on the flat panel.

Show the code
  1. One drawable panel that holds the buttons.
  2. Read :active in the paint handler and draw the panel as a mesh.
  3. The second route, for a touch press.
  4. Styles.

Colour input that recolours its own scene

The round lamp is an <input type="color">. Tap it to choose a colour, or use the buttons, which only write its value. The light on the wall and on the card is that colour.

Paint sample

White card, black text and four pigments.

The card is drawn in its own colours and then multiplied by the light, so a red light turns the green and blue pigments nearly black. The input is drawn last, so it shows the colour that was chosen and not the lit one.

Show the code
  1. Read input.value in the paint handler and multiply the scene by it.
  2. Styles.

Liquid progress bar

A <progress> element drawn as a tank. The buttons write its value, or remove it to make the bar indeterminate. The level follows on a spring and the surface is stirred by how fast it moves.

35%

The tank's outline is the element's own: the element is drawn first and the liquid is filled with source-atop, which keeps it inside the pixels the element painted. The percentage is read from progress.position.

Show the code
  1. Read position in the paint handler and fill inside the element's picture.
  2. Styles.

Search field that focuses the scene

A search field above six links. Tap the field: the links blur, dim and shrink. Type, for example se, and the links whose text matches come back sharp. Tap outside the field to leave it.

StartThe raw API in 60 lines Elements180 elements in a canvas SelectPickers drawn by a canvas SelectionHighlight effects LensFourteen magnifiers InstrumentsControls as machines

The links are real links at every stage, and a blurred link can still be tapped. The focus ring that widens round the field is drawn by the canvas, because an outline is outside an element's picture.

Show the code
  1. The field and each link are drawable children of the canvas.
  2. Read :focus and the value in the paint handler, and blur what doesn't match.
  3. Styles.

How it works

The browser raises paint on a drawable canvas when the picture of one of its drawable descendants changes. Typing changes a textarea's picture, :active and :focus styles change a button's or a field's, and a new value changes a colour swatch or a progress bar. So the paint handler is called at the moments an effect needs, and it can read the state from the control:

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 controls 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, with a mouse, a keyboard and emulated touch. Not yet run on a phone.