Use it: the smallest working markup for nine drop-in elements
Nine elements from this site's libraries that work on another page with one script tag and a few lines of markup. Each
box below runs the markup shown under it. Every one here draws with a 2D canvas, so the page opens no WebGL context.
The shader attribute fx has its own block on /shader-css/.
The libraries are served with Access-Control-Allow-Origin: *. They need Chrome with the HTML-in-canvas API. Without it each element leaves its children as plain HTML.
<effect-frame>
Draws its children through an effect. Move the pointer, or a finger, over the form. One 2D canvas. The experiments with it are on /nested-frames/.
<script type="module" src="https://html-in-canvas.page/lib/effect-frame.js"></script>
<effect-frame id="useFrame" effect="glass" amount="0.7" style="height: 170px">
<form onsubmit="event.preventDefault()" style="padding: 14px">
<h3 style="margin: 0 0 6px; font-size: 22px">Harbour dues</h3>
<p style="margin: 0 0 10px">One night alongside, boats under 10 m.</p>
<label>Boat <input name="boat" value="Kittiwake" style="width: 130px; height: 36px"></label>
<button style="height: 40px">Pay</button>
</form>
</effect-frame>
<selection-fx>
Draws its own highlight on the text the reader selects. Select a few words. marker is a 2D effect. The experiments with it are on /selection/.
The wind backed to the south-west in the afternoon and the tide turned in the Sound an hour later.
<script type="module" src="https://html-in-canvas.page/lib/selection-fx.js"></script>
<selection-fx id="useSelection" effect="marker" style="--selection-fx-color: #f59e0b">
<p style="margin: 0; padding: 12px; font-size: 18px; line-height: 1.5">The wind backed to the south-west in the afternoon and the tide turned in the Sound an hour later.</p>
</selection-fx>
<glyph-field>
Text whose letters fly apart and come back while it stays ordinary text. Move the pointer over it, or press the button. The experiments with it are on /particles/.
Small boats
Notes on tides, knots and weather.
<script type="module" src="https://html-in-canvas.page/lib/glyph-field.js"></script>
<glyph-field id="useGlyph" pointer="repel" style="display: block; height: 130px">
<h3 style="margin: 0; padding: 14px 12px 4px; font-size: 26px">Small boats</h3>
<p style="margin: 0; padding: 0 12px">Notes on <a href="/start/">tides</a>, knots and weather.</p>
</glyph-field>
<button type="button" onclick="document.getElementById('useGlyph').explode({ power: 1.2 })" style="min-height: 40px">Explode</button>
<select picker>
A select whose picker is a drum drawn by a canvas. The options stay real <option> elements. The experiments with it are on /select/.
<script type="module" src="https://html-in-canvas.page/lib/select-picker.js"></script>
<label>High water
<select id="useSelect" name="time" picker="wheel">
<option>05:40</option><option>06:12</option><option selected>06:45</option><option>07:20</option>
<option>07:55</option><option>08:30</option><option>09:05</option>
</select>
</label>
<canvas-slot>
Children with a slot name are drawn by your own function. Here the card is drawn turned, and its checkbox still works. The experiments with it are on /slot/.
<script type="module" src="https://html-in-canvas.page/lib/canvas-slot.js"></script>
<canvas-slot id="useSlot" style="display: block; height: 150px">
<label slot="card" style="display: block; width: 250px; padding: 14px; background: #fde68a; color: #1c1917; border-radius: 8px">
<input type="checkbox" checked> Reef the main at force 5
</label>
</canvas-slot>
<script type="module">
await customElements.whenDefined('canvas-slot');
document.getElementById('useSlot').onrender = ({ ctx, draw }) => {
ctx.translate(40, 50);
ctx.rotate(-0.08);
draw('card', 0, 0);
};
</script>
<dom-portal>
Shows one live element a second time. Type in either copy: there's one input. The experiments with it are on /portal/.
The same form at 0.7 scale:
<script type="module" src="https://html-in-canvas.page/lib/dom-portal.js"></script>
<form id="usePortalHome" onsubmit="event.preventDefault()" style="padding: 12px; width: 240px; border: 1px solid; border-radius: 8px">
<label>Berth <input name="berth" value="C14" style="width: 90px; height: 36px"></label>
</form>
<p style="margin: 8px 0 4px">The same form at 0.7 scale:</p>
<dom-portal id="usePortal" for="usePortalHome" scale="0.7"></dom-portal>
<dom-lens>
A magnifier over live markup. Move the pointer, or drag a finger. pipeline="2d" keeps it to a 2D canvas. The experiments with it are on /lens/.
| Oban | 06:12 | 3.9 m |
| Tobermory | 06:31 | 4.2 m |
| Mallaig | 06:58 | 4.6 m |
<script type="module" src="https://html-in-canvas.page/lib/dom-lens.js"></script>
<dom-lens id="useLens" mode="magnify" zoom="2" radius="70" pipeline="2d">
<table style="border-collapse: collapse; font-size: 13px; margin: 10px">
<tr><td style="padding: 4px 10px">Oban</td><td>06:12</td><td style="padding: 4px 10px">3.9 m</td></tr>
<tr><td style="padding: 4px 10px">Tobermory</td><td>06:31</td><td style="padding: 4px 10px">4.2 m</td></tr>
<tr><td style="padding: 4px 10px">Mallaig</td><td>06:58</td><td style="padding: 4px 10px">4.6 m</td></tr>
</table>
</dom-lens>
<input list picker>
The suggestions of a datalist drawn as pills by a canvas in a popover. Type a letter. The experiments with it are on /datalist/.
<script type="module" src="https://html-in-canvas.page/lib/datalist-picker.js"></script>
<label>Harbour
<input id="useDatalist" list="useHarbours" picker="chips" placeholder="Type a harbour" style="height: 40px">
</label>
<datalist id="useHarbours">
<option value="Oban"></option><option value="Mallaig"></option><option value="Portree"></option>
<option value="Tobermory"></option><option value="Tarbert"></option>
</datalist>
<input type="time" picker>
A time input whose picker is a clock of real buttons drawn by a canvas. Tap the field. The experiments with it are on /inputs/.
<script type="module" src="https://html-in-canvas.page/lib/input-pickers.js"></script>
<label>Departure
<input id="useClock" type="time" picker="clock" value="06:45" style="height: 40px">
</label>
How it works
The markup in each box is in this page's own source, between two comments. The listing under the box is the same text with the script tag of the library put before it. A live check compares the two. This page loads each library when its section comes near the screen, so on your own page the element starts sooner than it does here.
Show the code
Live checks
These run after a tap.
Findings
Measured in headless Chromium 157 on 2026-11-22. Not yet run on a phone.
- Nine elements start from one script tag and the markup shown: each was upgraded or taken over by its library, and the nine listings match the markup that runs.
- By touch at 412 px: typing in the field inside
<effect-frame>worked, a double click selected a word in<selection-fx>, the link in<glyph-field>was found by a hit test, a tap opened the wheel of the select and the clock of the time input, a tap unticked the checkbox on the turned card of<canvas-slot>, typing in the copy made by<dom-portal>changed the one input, and typing a letter opened the datalist's pills. - Writing this page found a fault in
select-picker.js: an option markedselectedin the markup was lost when the library moved the options into its canvas, and the last option became the value (09:05 where the markup says 06:45). The library now keepsselectedIndexacross the move. - The page opens no WebGL context: every element here draws on a 2D canvas,
<dom-lens>because ofpipeline="2d". - Not verified: Chrome 159 on Android, and the snippets on a page of another origin. The libraries were loaded from this origin in every test.