Focus order drawn as a path
The canvas draws three groups of links, fields and buttons. Over them it draws the order in which the Tab key visits them: a numbered
line from stop to stop. A step that goes against reading order is orange. Change the arrangement, give a button a
tabindex, or leave a group out of the picture, and the line is worked out again. Press Tab, or use the two buttons under
the picture, to move focus along it.
Show the code the Tab order from the DOM, the positions from the picture
- The markup. Three children of one canvas. Nothing in it is there for the path.
- The Tab order. Which elements are stops, and in what order.
- Where each stop is. The rectangle the browser reports for a drawn element is where it was drawn.
- One frame. Draw the groups, then the path over them, in the same canvas.
- Drawing the path.
- Which elements were drawn. A wrapper round
drawElementImage()keeps a list for the frame. - Comparing with the real Tab key. Each Tab press you make is compared with the path.
How it works
- The order is worked out from the DOM. An element is a stop if its
tabIndexis 0 or more, or it is an editing host, or it is a scroll container with nothing focusable inside. It's left out if it's disabled, inert, not rendered, or a radio button that isn't the checked one of its group. Stops with a positivetabindexcome first, lowest first. The rest follow in tree order. - The position of each stop is its
getBoundingClientRect(). For a child of a drawable canvas that is the box the element was last drawn in, so the line follows the picture when a group is drawn somewhere else or turned. - The page wraps
drawElementImage()and keeps the list of elements drawn in the frame. A stop that isn't inside one of them isn't in the picture. Its number goes in the red strip at the bottom. - The path is drawn after the groups, in the same 2D context. The dashes move in the direction of travel unless the system asks for reduced motion.
- "Previous stop" and "Next stop" call
focus({ focusVisible: true })on the neighbouring stop of the path. They don't test the path. The Tab key does: the page notes each Tab press and compares the element that received focus with the next stop on the path.
Live checks
Each check builds a small canvas of its own in a corner of the window. The picture above isn't touched.
| Result | Experiment | Detail |
|---|
Findings
From Chromium 157, headless, on 2026-11-21. The rows above say what your browser does.
- Works: the order from the DOM matches the Tab key. A script pressed Tab through this page in six arrangements (the options above, and the details open) and the focused element was the next stop of the path every time. The script is
tools/devtools-pages/verify.mjs. - Limit: a positive
tabindexis ordered in the whole document. Withtabindex="1"on "Sign up", the path shows it as stop 1. That's its place among the stops of the canvas. In the page it is the first stop of the whole document, before the menu bar, and Tab doesn't reach it from the field before the canvas. - Works: the path follows the picture. Drawing the groups in another order or at an angle moves the stops, because
getBoundingClientRect()reports the drawn box. The Tab order doesn't change: it follows the DOM. "last group drawn first" shows the result, a path that starts at the bottom of the picture. - Limit: under a rotation the reported box is the bounding box. The line still passes through the centre of each stop, since the centre of the bounding box of a turned rectangle is the centre of the rectangle. The outline round a stop is larger than the stop.
- Found: an element that isn't drawn is still a Tab stop. Tab moves focus to it and nothing in the picture shows where focus is. It also keeps the hit box of the last time it was drawn. Setting
inerton it takes it out of the order. The "Last group" menu shows the three states. - Found:
tabIndexreads -1 for two kinds of Tab stop. An element withcontenteditableand a scroll container with nothing focusable inside are both stops for the Tab key, and both reporttabIndex-1. The rule checks for them separately. - Not covered: shadow trees, slots, frames,
focusgroupandreading-flowaren't followed by the rule. A<video controls>counts as one stop. - Not verified here: a phone has no Tab key. The "next" key of the on-screen keyboard and a screen reader's swipe order weren't run. Connect a keyboard to the phone and press Tab: the status line counts how many presses matched the path.