CORE JSC

International Technology Partnership

UI/UX

Fixing Keyboard Tab Order That Doesn't Match Visual Order After Using CSS Flexbox or Grid "order"

Reordering cards or form fields visually with the CSS `order` property is a quick way to adjust a responsive layout without touching the markup. But pressing Tab still moves through the elements in their original DOM order, not the order they now appear on screen — and for keyboard users, that mismatch turns a clean-looking layout into a confusing, unpredictable one.

Core JSC Team·October 14, 2026
UI/UXAccessibilityCSSKeyboard NavigationWeb Development

The Problem

A grid of cards, or a set of form fields, is visually reordered using the CSS order property inside a flex or grid container — maybe to put a "Submit" button after a field that was added later in the markup, or to rearrange a responsive layout at a particular breakpoint without duplicating HTML. Visually, everything looks correct: the elements appear exactly where they're supposed to. But a keyboard user tabbing through the page jumps around unpredictably — landing on a field near the bottom of the screen, then the next Tab press jumps back up to something near the top. Nothing is broken in the sense of a console error; the layout and the navigation order have simply come apart from each other.

Why It Happens

The CSS "order" property changes paint order, not document order

The order property is explicitly a visual/layout feature: it tells the browser where to paint a flex or grid item relative to its siblings, and it does that without touching the underlying DOM at all. The element is still exactly where it was written in the HTML; the browser is just told to draw it somewhere else on screen. Keyboard navigation, however, doesn't follow paint order — it follows document order, walking through focusable elements in the sequence they actually appear in the DOM tree.

Sighted mouse users never notice the gap, which is why it survives most manual testing

A mouse click goes directly to whatever's visually under the cursor, regardless of DOM position, so a mouse-only test pass of the same page looks completely fine — every interaction lands exactly where expected. The mismatch is invisible to anyone not specifically tabbing through the page or using a screen reader, which reads content largely in document order as well, so it's a category of bug that's exceptionally easy for a visually-driven QA pass to miss entirely.

A reordered layout at one breakpoint can be correct at another, making the bug responsive-width-dependent

A common pattern is applying order values only within a specific media query, to rearrange a layout for mobile while leaving desktop in its natural document order. That means the bug can be completely absent at one viewport width and fully present at another, so testing tab order only at a single screen size — commonly, whatever size the developer's own monitor happens to be — can miss it even when the developer is specifically checking keyboard navigation.

The Fix

1. Treat "order" as cosmetic-only, and reorder the actual markup whenever the visual change is meant to be permanent

<!-- Instead of relying on CSS order to move the submit button after email: -->
<form>
  <input name="submit-placeholder" />  <!-- originally first in markup -->
  <input name="email" />
</form>

<!-- Reorder the actual elements so DOM order already matches the intended visual and tab order: -->
<form>
  <input name="email" />
  <input name="submit-placeholder" />
</form>

Whenever the reordering reflects the layout's actual, permanent intent — this field really should come after that one, in every context — fixing the markup itself is the most direct solution, because it makes DOM order and visual order identical by construction, with no CSS-level special case for assistive technology to fall out of sync with later.

2. When the order genuinely needs to differ only at specific breakpoints, verify tab order at each one explicitly rather than assuming it's fine

/* order only applied within this breakpoint — remember tab order needs checking here specifically */
@media (max-width: 600px) {
  .submit-button { order: 2; }
  .email-field { order: 1; }
}

If a responsive-only reorder is genuinely necessary — the logical layout really is different on mobile versus desktop — the fix isn't to avoid order entirely, but to explicitly test keyboard navigation at that specific breakpoint rather than assuming a desktop-width manual check covers it, since the mismatch is breakpoint-specific by construction.

3. Use CSS Grid's named template areas instead of "order" when the goal is purely a responsive rearrangement

.form-grid {
  display: grid;
  grid-template-areas: "email" "submit";
}
@media (max-width: 600px) {
  .form-grid { grid-template-areas: "submit" "email"; }
}
.email-field { grid-area: email; }
.submit-button { grid-area: submit; }

Grid template areas have the exact same practical effect as order — visual rearrangement without touching markup — and share the same disconnect from DOM order, so this isn't a fix for the underlying issue by itself; it's mentioned because teams sometimes reach for order specifically to solve a problem template areas handle more declaratively, and the same breakpoint-specific tab order verification from fix 2 still applies either way.

4. Audit existing "order" usage across the codebase as a dedicated pass, since each instance is a candidate for this exact bug

grep -rn "order:" --include="*.css" --include="*.scss" src/ | grep -v "order: none|z-index|border|border-radius"

Because every use of order is independently a place where document order and visual order can diverge, a targeted search across the stylesheet is a more reliable way to find the full set of affected components than relying on tabbing through every page of the application and hoping to notice each one.

Why This Works

Every one of these fixes addresses the same root cause from a different angle: keyboard and screen-reader navigation follow document order, while order and grid template areas only ever change paint order, so any reliance on them for layout inherently risks this split. Reordering the markup directly removes the split for good when the new visual order is the real, permanent intent. Explicitly testing at the specific breakpoint where a reorder applies catches the cases where the split is responsive-width-dependent and therefore easy to miss in a single manual pass. And auditing all existing order usage turns "hope nothing's broken" into a concrete, checkable list of exactly which components need that verification.

Conclusion

A layout that looks correct but navigates unpredictably with the keyboard usually isn't a bug in the navigation logic — it's the CSS order property (or an equivalent like grid template areas) changing where something is painted without changing where it lives in the DOM, which keyboard and screen-reader navigation both still follow. Treat visual reordering as permanent by fixing the markup itself whenever possible, explicitly verify tab order at each breakpoint where a responsive-only reorder genuinely is necessary, and run a targeted audit of every existing order usage rather than relying on spot-checking individual pages to catch the gap.