Source order and reading order
Overview
Flexbox and grid can put any element anywhere on screen, regardless of where it is in the HTML. That’s powerful — and dangerous. Many people don’t experience your page visually:
- Keyboard users press Tab to move between links, buttons and form fields.
- Screen-reader users hear the page read out from top to bottom.
- Voice-control users say what they see, then expect the next item to follow.
All of these follow the DOM order — the order of the HTML. When the visual layout disagrees with it, the experience breaks.
How the mismatch happens
Any of these can move content visually without moving it in the DOM:
.item { order: -1; } /* flex and grid */
.row { flex-direction: row-reverse; } /* reverses the visual order */
.col { flex-direction: column-reverse; }
.feature { grid-column: 3; grid-row: 1; } /* explicit placement */
.grid { grid-auto-flow: dense; } /* backfilling */
.a { grid-area: sidebar; } /* template areas in a different order */None of them changes what the browser considers “next”. Imagine a toolbar with row-reverse: it looks like Save, Cancel — but Tab goes Cancel, Save, and a screen reader announces them in that order too. A sighted keyboard user sees the focus ring jump right-to-left; a screen-reader user may hear “Cancel” first and act on it.
Why it matters: WCAG
The Web Content Accessibility Guidelines include two criteria for this:
- 1.3.2 Meaningful Sequence (A): when the order affects meaning, the reading order must be determinable — the DOM order must make sense.
- 2.4.3 Focus Order (A): focusable elements must receive focus in an order that preserves meaning and operability.
A small mismatch (a decorative image moved above a heading) is harmless. A form whose fields are focused in a different order than they appear, or a “Next” button that comes before the content, is a real failure.
Rules of thumb
1. Get the HTML order right first
Write the HTML in the order a person should read and use the content. Ask: “if CSS failed to load, would this order make sense?” Then use layout to arrange it.
Most layouts need no reordering at all: with grid template areas, the visual arrangement is defined in CSS while the HTML stays logical — header, nav, main, aside, footer.
2. Rearranging non-interactive content is lower risk
Moving a decorative image (alt="") above a heading doesn’t change what screen readers announce or where focus goes. Moving a heading below its paragraph, or a button before the content it acts on, does.
3. Don’t use reversal for convention
A common example is dialog buttons: some platforms put the primary button on the right. Write the buttons in the HTML order you want people to encounter them, then align them with justify-content: flex-end — not row-reverse.
4. Be careful with responsive reordering
Changing the visual order at a breakpoint means the reading order is right at one size and wrong at another. If a sidebar should appear first on desktop but after the content on mobile, decide which order is more important for reading and use that in the HTML.
5. Test with the keyboard
Click in the address bar, then press Tab repeatedly. Does the focus ring move in a sensible order — generally left to right and top to bottom? Does it ever jump backwards or off-screen? This 30-second test catches most problems. A screen reader (VoiceOver on Mac/iOS, NVDA on Windows, TalkBack on Android) catches the rest.
Never use tabindex to fix it
tabindex="1", "2", "3"… on elements forces a tab order, but it applies to the whole page: all positive-tabindex elements come before everything else, and it doesn’t affect screen-reader reading order at all. It creates more problems than it solves. Use tabindex="0" (add to the natural order) and tabindex="-1" (focusable by script only) — never positive values.
reading-flow: a future fix
The CSS reading-flow property tells the browser to make focus and reading follow the visual order of a flex or grid container’s items:
.toolbar {
display: flex;
flex-direction: row-reverse;
reading-flow: flex-visual; /* Tab follows what you see */
}
.grid {
display: grid;
reading-flow: grid-rows; /* row by row, as laid out */
}There’s also reading-order for individual items. As of December 2026 these are supported only in Chromium browsers (Chrome and Edge 137+), not in Firefox or Safari. They’re a useful safety net where available, but the HTML order is still what most of your users get — so keep getting it right.
One-line rule: if the order of things means something, put that order in the HTML. Use CSS to arrange space, not to tell the story.
Fix a card whose tab order jumps around
In the starter, the card looks right — image, then title, then actions in the order Preview, Enrol — but it was done with order and reversed flex direction, so the HTML order is wrong and Tab moves Enrol → Preview, and screen readers read the price before the title. Rewrite the HTML into a logical order (title, image, price, then Preview, Enrol) and use CSS to put the image visually at the top without order. Remove every use of order and row-reverse. The visual result must stay the same.
<article class="card">
<p class="price">$29</p>
<div class="actions">
<a href="#">Enrol</a>
<a href="#">Preview</a>
</div>
<h3>Grid layout</h3>
<img alt="" />
</article>
<style>
* { box-sizing: border-box; }
.card { display: flex; flex-direction: column; inline-size: 20rem; gap: 0.5rem; border: 1px solid #ccc; padding: 1rem; }
.card img { order: -2; display: block; inline-size: 100%; aspect-ratio: 16 / 9; background: #c9d8f8; }
.card h3 { order: -1; margin: 0; }
.price { margin: 0; }
.actions { display: flex; flex-direction: row-reverse; justify-content: flex-end; gap: 1rem; }
</style><article class="card">
<h3>Grid layout</h3>
<img alt="" />
<p class="price">$29</p>
<div class="actions">
<a href="#">Preview</a>
<a href="#">Enrol</a>
</div>
</article>
<style>
* { box-sizing: border-box; }
.card {
display: grid;
grid-template-areas:
"image"
"title"
"price"
"actions";
inline-size: 20rem;
gap: 0.5rem;
border: 1px solid #ccc;
padding: 1rem;
}
.card img { grid-area: image; display: block; inline-size: 100%; aspect-ratio: 16 / 9; background: #c9d8f8; }
.card h3 { grid-area: title; margin: 0; }
.price { grid-area: price; margin: 0; }
.actions { grid-area: actions; display: flex; gap: 1rem; }
/* Moving the decorative image above the heading is fine: it has alt="" and
isn't focusable, so the reading and focus order are unaffected. */
</style>Summary
- Keyboard focus and screen readers follow the DOM (HTML) order, not where things appear visually.
order,row-reverse,column-reverse, grid placement anddensecan make visual and reading order disagree.- WCAG requires a meaningful reading order and a focus order that preserves meaning.
- Fix the HTML first; use CSS rearrangement only for non-interactive or decorative content, or small, harmless shifts.
reading-flowcan make focus follow the visual order of flex and grid items, but it’s Chromium-only — don’t rely on it yet.