Where does Tab go?
5 November 2026 2 min read
Two shop screens that look the same. Press Tab and the focus takes completely different routes. The path is drawn on top.
- Accessibility
- Keyboard
- HTML
A mouse user sees a layout. A keyboard user gets a sequence. When the two disagree, the page looks fine and feels broken, and nobody sees it in a screenshot.
Both screens are the same shop: a header, three filter chips, two products, a checkout button. The numbered dots show the order in which Tab visits the real elements. Switch the path off, click into a panel and press Tab to see the focus ring follow it.
Three ways the order drifts
The left screen has all three, on purpose.
- Visual order is not the DOM order. CSS
order,flex-direction: row-reverseand grid placement move things on screen. Tab follows the HTML. The chips are reversed, and the second product is placed first. - A positive
tabindex. The cart button hastabindex="1", which sends it to the front of the whole page, ahead of the logo. It looked like a shortcut when someone added it. - Focus order was never checked after a redesign. Each change was fine alone.
.chips { display: flex; flex-direction: row-reverse; } /* looks reversed, tabs in DOM order */
.card { order: 2; } /* drawn first, visited second */
What the right side does
Nothing clever. The HTML is written in the order people read it, and the CSS does not reorder it. There is no tabindex above zero.
<button type="button" class="cart">Cart</button> <!-- no tabindex needed -->
If you have to reorder visually, change the HTML to match. The CSS specification warns about this itself: reordering is visual only, and it does not change the order for keyboards and screen readers.
How the demo finds the path
It collects the focusable elements, puts anything with a positive tabindex first, then everything else in document order. That is the same rule a browser applies. The "jumps backwards" counter counts steps that go back up the screen, or against the reading direction on the same row.
const list = [...root.querySelectorAll('a[href], button, input, [tabindex]:not([tabindex="-1"])')];
const positive = list.filter((e) => e.tabIndex > 0).sort((a, b) => a.tabIndex - b.tabIndex);
const natural = list.filter((e) => e.tabIndex === 0);
const order = [...positive, ...natural];
A cheap habit
Once per release, put the mouse away and tab through the main flow. It takes two minutes and it finds more than most audits. Browser developer tools can also draw the order for you, and a small script like this one works in any project.
About the counter
A backward step is not always wrong, and a clean count does not prove a good order. The counter finds drift. Whether the sequence makes sense for the task is still a human call.
Related
- Focus is part of the design A dialog that works with a mouse is half a dialog. Where keyboard focus goes when it opens, while it is open and when it closes decides whether anyone else can use it.
- Translate it until it breaks The same small panel, built twice. Switch to German, Arabic or 200 % text and count what breaks.