Notes

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.

Click into a panel, then press Tab. The ring follows the same order as the numbers.

Looks right, tabs wrong

Drifted

0 jumps backwards · 0 stops

Tab order follows the layout

Aligned

0 jumps backwards · 0 stops

Live demo. Everything runs in your browser. Now try to break it.
TabPath.svelte, 186 lines

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-reverse and 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 has tabindex="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

How bright was it?

Five lamps and an optional line. Feedback, a bug, an idea, anything. I read every one and sum them up once a month.

Pick a lamp

Stored without name, address or cookie, and deleted after a year. Details in the privacy notice.