Focus trail and heading outline drawn by a canvas
Two accessibility views from the element catalogue, and two more on the same form. A canvas draws a form and, when focus moves, a ring that travels from the control that lost focus to the one that gained it. The same canvas can mark the size of each touch target and draw a line from each label to its control. A second canvas draws an article with a list of its headings beside it. Each row of that list is the heading's own pixels, drawn a second time.
Focus ring that leads the eye
Tap a field or a button in the form, press Tab, or use "Next stop". The ring flies from the old position to the new one and the rest of the form is shaded. "Target sizes" and "Label lines" draw two more views over the same form.
The canvas learns that focus moved from focusin, which names both elements. It reads where each one was drawn from getBoundingClientRect(). When the ring arrives, the canvas draws that rectangle of the form's picture a second time, 12% larger, for a third of a second. The form has four faults on purpose: a 20 px button, a field with only a placeholder, a label whose for matches nothing, and the field that label was meant for.
Show the code focusin, two rectangles, and a ring drawn between them
- The markup. One
drawableform. Nothing in it is there for the views. - Hearing that focus moved.
- One frame of the ring.
- The paint handler. The form, then the views, then the ring.
- Drawing the focused control enlarged. A piece of the form's picture, and a draw with no ink to put the hit box back.
- The shade, the tail and the ring.
- Target sizes.
- Label lines.
- Styles.
Heading outline beside the page
Scroll the article with a finger or the wheel. The list on the right has one row for each heading. Tap a row to go to that heading. Change a heading with the controls under the picture and its row changes, because the row is drawn from the article's picture.
The rows aren't text drawn by the canvas. Each one is drawElementImage(article, sx, sy, sw, sh, dx, dy, dw, dh) with the rectangle of one heading, so the font, the wrapping and any edit are the article's. The links that take the taps are children of the canvas drawn with globalAlpha = 0. Scrolling is the browser's own: the canvas is position: sticky inside a scroll container and draws the article at minus scrollTop.
Show the code headings from the DOM, rows from the article's picture
- The markup. A scroll container, a sticky canvas, the article and an empty list.
- Collecting the headings.
- One link per heading.
- Where each heading is in the article.
- The paint handler. Links with no ink, the rail, then the article.
- Drawing the rail.
- Going to a heading.
- Styles.
How it works
- Each picture is one 2D canvas with
content="drawable". Its children are ordinary HTML and thepainthandler draws them withdrawElementImage(). Everything else in the picture (ring, tail, shade, target boxes, label lines, the rail) is drawn after them in the same context. - Focus:
focusinbubbles to the canvas.event.targetis the element that gained focus andevent.relatedTargetthe one that lost it. When the old element is outside the canvas, the ring starts at the nearest point of the canvas edge. The flight lasts 220 to 560 ms, longer for a longer move. Withprefers-reduced-motionthe ring is drawn at the new position at once and a straight line with an arrow head shows where it came from. - Positions:
getBoundingClientRect()of a canvas child, or of an element inside one, reports where it was last drawn. "Drawn at 60%" draws the form smaller, and the ring, the target boxes and the label lines follow without any code for it. - Target sizes: every link, button and form control is measured as drawn. A side under 24 CSS px is red, under 48 px amber. 24 is the size in WCAG 2.2 "Target Size (Minimum)". 48 is the size Android asks for. The view measures the control's own box. It doesn't add the label of a checkbox, which also takes the tap.
- Label lines: a line runs from the words of each
<label>to its control, found throughcontrol.labels. The words are measured with aRange. A control named only byaria-labelhas a dashed outline and the name on a plate, because nothing visible names it. A control with only a placeholder is amber, a control with nothing is red, and a label whoseformatches no control is marked. - Heading outline: the headings are collected from the DOM with a rule of about 15 lines. A
MutationObserveron the article runs it again after an edit. The rail's rows are rectangles of the article's picture. The article is drawn last and whole, which puts its hit box back after the pieces. - The article is taller than the canvas. The canvas is
position: stickyin a scroll container, with a spacer of the article's height after it. Ascrolllistener asks for a paint, and the handler draws the article at minusscrollTop. Tapping a row callsscrollTo()on the container andfocus()on the heading, so the ring flies from the row to the heading. - Without the API, or after a lost context, both canvases are replaced by their children as plain HTML. The outline is then an ordinary list of links.
Live checks
Each check builds a small canvas of its own in a corner of the window. The checks that move focus run in a hidden copy of this page. The two pictures above aren't touched.
| Result | Experiment | Detail |
|---|
Findings
From Chromium 157, headless, on 2026-11-21. The rows above say what your browser does. Real key presses and touch events were sent by tools/a11y-views/check.mjs.
- Works: a focus ring is in the picture when the focused element is inside the drawable element. A 4 px red outline round a button inside a drawable
divwas found in the canvas pixels at the button's drawn position. Focus moving raised onepaintevent with thedivinchangedElements. - Limit: the ring is cut at the border box of the drawable element. A button in the corner of its drawable parent kept only the part of its ring that was inside the parent. An outline round the drawable element itself isn't in its picture at all, unless
outline-offsetis negative. - Found: no pixel change, no paint event. With
outline: noneon the focused element, moving focus raised nopaintevent. A trail that waits forpaintwouldn't start.focusinfired every time, withrelatedTargetset. - Works: the trail follows the picture. The start and the end of the trail were at the drawn positions of the two buttons when the fixture was drawn at half size and offset.
- Found: a control drawn smaller is a smaller target. A 40 px button drawn at half size took a hit only inside its 20 px drawn box. The target view reported 20 by 20.
- Works: label text measured with a
Rangefollows the picture at half size, so the line starts at the drawn words. - Works: a row of the outline is the heading's pixels. A piece draw of the article with the heading's rectangle put the heading's colour at the row. After the pieces, one whole draw of the article put its hit box back: a point on a link in the article returned the link.
- Works: links drawn with
globalAlpha = 0take the tap.elementFromPoint()at a row returned the link for that row, and the canvas pixels there came only from the canvas's own drawing. - Found: scrolling the container raises no paint event. The page asks for one from a
scrolllistener. Changing a heading's text raises one. Changingaria-levelraises none, so the outline is rebuilt from aMutationObserver. - Works: the Tab key scrolls the article by itself. Tab from above the canvas reached a link about 710 px down the article, below the 520 px canvas. The browser scrolled the container to 480 px, which put the link in the middle of the canvas. The page didn't move. The page has no code for this.
- Works: a finger drag on the drawn article scrolls the container. A 250 px drag moved
scrollTopby 235 px and the page by 0 px. - Not verified here: a phone and a screen reader. TalkBack moves its own accessibility focus, which isn't DOM focus. Whether
focusinfires when TalkBack moves to a control, and so whether the trail runs, wasn't measured. The line under the first picture countsfocusinevents: move through the form with TalkBack and read the count. The frame rate of the article scrolling under a finger wasn't measured on a phone either.