Form controls drawn as instruments

Five ideas from the element catalogue, built. In each one the canvas draws a form control as a different machine, and the real control still holds the value, takes the keyboard and does its own validation. Turn the knob, type in the counter, press Next with an empty field, and drag the clock hands. The line under each canvas is read from the form.

Rotary switch from a radio group

Five radio buttons. Their labels are drawn round a knob, and the knob points at the checked one. Tap a label, drag the knob, or focus a radio and use the arrow keys.

Fan speed

The radio group is the only state. Arrow keys, the one-checked rule and the form value are the browser's. The page adds the knob: it reads which radio is checked, and a drag checks the radio of the nearest position.

Show the code
  1. Mark each label drawable. The form and the fieldset aren't drawn.
  2. Draw the knob from the checked radio and the labels round it.
  3. A drag on the knob checks a radio.
  4. Styles.

Odometer for a number input

One <input type="number">. Tap the wheels and type, use the up and down arrow keys, or press the buttons. The wheels roll to the new value.

The input's text is transparent and the canvas draws the digits, because the picture of the old value is gone once the value changes. The input still draws the caret and the selection, and letter spacing puts each character over its wheel. Its focus ring is drawn by the canvas.

Show the code
  1. Make one character as wide as one wheel.
  2. Draw the wheels from the value, then the input on top.
  3. Styles.

Form on a prism, one fieldset per face

A three-step form. Next and Back turn the prism. Press Next with a field empty, or type a name on the first face and press Enter.

1. Who

2. What

3. Confirm

Validation messages, :invalid styles, the Enter key and the submitted data are the form's own. The page adds the turn, sets inert on the two faces that are turned away, and turns to a face when the browser reports an invalid field on it.

Show the code
  1. One form, three drawable fieldsets.
  2. Draw the faces in strips while the prism turns, and flat when it rests.
  3. Turn on Next, on Back and on invalid.
  4. Styles.

Dial gauge from a <meter>

The arc is the picture of a <meter> element, bent. Move the slider through the low and high marks, then change where the optimum is (the green mark): the browser picks the colour of the bar.

62 out of 100

The element supplies the bar, its track and its colour rules. The page adds the bend, the needle and the tick labels, which it reads from the element's attributes.

Show the code
  1. Draw the meter in 100 slices round an arc, then the needle.
  2. Styles.

Clock hands from a time input

One <input type="time">, drawn under a clock face. Drag either hand, or type in the field. Taking the minute hand past 12 changes the hour.

The input holds the time and is the control a keyboard or a screen reader uses. The page draws the face from valueAsNumber and writes value while a hand is dragged.

Show the code
  1. Draw the face and hands from the value.
  2. A drag writes the value.
  3. Styles.

How it works

Each canvas holds the real control as a descendant marked drawable. A paint handler draws the machine with ordinary 2D calls and draws the control, or parts of it, with drawElementImage(). That call also moves the control's hit region to where it was drawn, so taps, the caret and the focus order need no code. Three techniques are used more than once:

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.

Findings

Measured in headless Chromium 157 on 2026-11-21, with a mouse, a keyboard and emulated touch.

On a phone (Chrome 159 on Android, reported 2026-11-21): the first version of this page lost its canvases repeatedly: a white box with a broken-picture icon, then a white screen, then an empty canvas. The cause was found later on the phone by another experiment on this site: a drawable 2D canvas created with willReadFrequently: true, once drawn into and read, loses every 2D context on the page about every half second. The first version's live checks made such canvases on load. This version reads pixels from a drawImage() copy, keeps the checks behind a tap, and after one lost context stops drawing and shows every control as plain HTML. Whether that ends the losses on the phone isn't verified.