Search topics
Focus order that jumps around the page
CSS reverses a row of buttons on screen while the markup keeps the old order, so Tab moves against the layout.
flex-direction: row-reverse The problem
Keyboard users watch focus move against the layout, lose their place, and can press the wrong button
A stationery shop's checkout ends with three actions at the right-hand end of a bar. On screen, from left to right, they read "Place order", "Save for later" and "Back to basket". Someone using a keyboard tabs into the bar. Focus lands on "Back to basket", the one on the far right. The next Tab moves left to "Save for later", and the next to "Place order". The ring travels against the direction the page reads, and the person watching it is never sure which button comes next. A second version of the same checkout has the buttons in the right order, but someone gave them tabindex 1 to 3 to make the main action quick to reach. Now the first Tab on the page jumps straight past the discount code to Place order, and focus only comes back up to the field after Back to basket.
The design wanted the main action first, so the stylesheet puts the row in flex-direction: row-reverse. The markup still lists the actions as back, save, place. The browser tabs through the markup, not through the pixels, so the order on screen and the order of focus are opposites. WCAG 2.4.3 asks for a focus order that preserves meaning and operability. Here the meaning is a row that reads one way, and focus travels the other. A positive tabindex breaks the same promise from the other side: browsers visit every element with a positive value before anything else on the page, so those buttons are pulled out of the flow of the page.
Anyone who expects focus to start on the first button they see can press Enter on "Back to basket" instead, and leave the checkout.
4 of 10 groups affected
- No vision (affected)
- Low vision (affected)
- Colour vision (not affected)
- No hearing (not affected)
- Hard of hearing (not affected)
- No speech (not affected)
- Motor (affected)
- Reach, strength (not affected)
- Cognitive (affected)
- Seizures (not affected)
- Limited manipulation Keyboard and switch users have only focus to tell them where they are, so a jumping order leaves them lost.
- Limited vision A screen magnifier user sees a small piece of the page, and a ring that leaps from the right edge to the left is easy to lose.
- Without vision Screen reader users hear the actions in markup order, which contradicts what a sighted colleague describes.
- Limited language, cognitive and learning abilities People who find reading hard lose the thread when Tab lands somewhere they did not expect, and have to work out where they are before going on.
Every control in the reversed bar is focusable, named and reachable, so a scanner has nothing to flag; only the positive tabindex is a value a rule can read, and axe's tabindex rule reports it. A check of the DOM sees a valid list. Finding the problem means comparing where each element is drawn with where it falls in the tab sequence, and few tools do that. Generated code can make it worse by adding order or row-reverse to match a mockup and leaving the markup alone.
What the checkers report
- axe DevTools
- Elements should not have tabindex greater than zero
- Lighthouse
- Some elements have a
[tabindex]value greater than 0
- Some elements have a
- WAVE
- Tabindex
Try it
Press Tab and watch which way focus moves
Broken 1: Tab from the discount code through the three buttons. Does focus move the way the page reads, top to bottom and left to right?
Broken 2: Tab into the checkout from above it. Where does focus land first, and when do you reach the discount code?
Apply a fix. Tab from the discount code through the three buttons again. Does focus move the way the page reads?
Broken Can you fix this?
The fix
Make the markup order and the layout agree
A row reversed in CSS
<div class="actions"> <a href="/basket">Back to basket</a> <button type="button">Save for later</button> <button type="submit">Place order</button></div>What is wrong2 points
- Focus moves against the way the row reads.
row-reverseshows the row as place, save, back from left to right, but focus visits back, save, place. - Screen readers announce the actions in the opposite order to the screen too. The CSS changed what people see and left the order that keyboards and screen readers use.
Markup that follows the design
<div class="actions"> <button type="submit">Place order</button> <button type="button">Save for later</button> <a href="/basket">Back to basket</a></div>How it is fixed2 steps
- List the actions in the markup in the order the design shows. Tab moves from "Place order" to "Save for later" to "Back to basket", left to right, as the page reads.
- Drop
row-reverseand the positivetabindexvalues, and keep the row at the right withjustify-content: flex-end. The look is unchanged.
This fixes both Befores and passes 2.4.3.
Why this fix: Write the source in the order it is read
Each passes, because in both the order on screen and the order of focus are the same. Reordering the markup keeps the design exactly as approved, and costs an edit to the template, and to any tests or snapshots that rely on it. Removing the reversal costs nothing in code but changes how the bar looks, so it needs the designer's agreement. Choose by which order is right for the content: if the markup order is the natural sequence and the reversal was only styling, remove the reversal; if the design is fixed, change the markup.
row-reverse is only one of several ways to get here. The order property, column-reverse, grid placement with grid-area or grid-row, floats and absolute positioning can all move an element on screen without moving it in the markup. Search for them next to anything focusable.
Do not repair the order with tabindex="1", "2" and so on. Elements with a positive value are visited first, ahead of everything else on the page, so the numbers pull the buttons out of the flow of the page and every element added later has to be numbered too. Use tabindex="0" for a custom control that must be focusable and -1 for something focused by script, as in the skip link guide.
Layouts that change at a breakpoint are the usual source of a second bug. A sidebar that moves below the content on a phone, or a card whose image moves above its heading, needs the same check at that width. Right-to-left languages should be handled with dir="rtl", which reverses the layout and the focus order together, rather than with row-reverse.
Order has to preserve meaning, not match every pixel. A decorative control that sits slightly out of line does not fail. A step that falls before the one it depends on does. Content that appears on demand, such as a menu or an error message, should be inserted next to the control that opened it, or take focus when it opens; for dialogs see the modal guide. The newer reading-flow CSS property can align the two in browsers that support it, but support is not yet universal, so fix the markup.
Verify the fix
4 checks, no mouse.
Test with: Keyboard, Screen reader, Zoom
Record the OS, browser and assistive-technology versions, the build, the date, and the actual result of each step. Repeat after layout or component styles change.
Limits
This is a starting pattern, not a guarantee for every application. It covers a static row of actions. Text that CSS moves away from its place in the markup, with nothing focusable in it, is covered in reading order that doesn't match the layout. A floating button, or the panel a button opens, written at the end of the page while it is drawn somewhere else, is covered in floating buttons and panels that keyboard focus reaches last. Data grids, carousels and widgets that move focus with arrow keys follow their own patterns and need their own checks. Whether an order preserves meaning is a judgement about the content, so test the complete journey on your real pages.
This is a recreated teaching example, not a finding about a named client. The code is a starting pattern: test it in your own product. No completed assistive-technology test is claimed here.
EaseWeb service
Fixed it? Keep it from coming back.
I turn guides like this one into rules your coding agents follow and checks your CI runs. Then I retest by hand with a keyboard and screen readers, periodically.