Full answer
order is a property for flex and grid items. Items are drawn sorted by their order value, lowest first, and the default is 0. Items with the same value keep their HTML order. Negative values are allowed, so order: -1 moves an item to the front.
It is easy to use. For example, a card can have the image after the text in the HTML, and order: -1 on the image shows it first on screen.
The problem is that order changes only the visual order. The DOM order stays the same. Keyboard focus, screen readers and the text cursor all follow the DOM order. If the screen shows A, B, C but the DOM is C, A, B, then Tab moves C, A, B. The focus appears to jump around, which is confusing, and it can fail accessibility rules that require a meaningful sequence.
Good practice:
- Put content in the DOM in the order that makes sense when read. Use
orderonly for small changes where focus order does not matter, such as a decorative item. - If the visual order must change for a screen size, check the tab order after the change.
- For very large changes, change the HTML.
flex-direction: row-reverseandcolumn-reversehave the same issue.
On screen the third link in the HTML is drawn first. When the Tab key is pressed, focus goes to the first link in the DOM, which is drawn in the second place, then to the next one, and the last focus lands on the link drawn at the left. The focus appears to jump from the second box to the third and then back to the first.
A simple check is to press Tab through your page and watch whether the focus ring moves in a path that makes sense.
<style>
.row { display: flex; gap: 8px; }
.row a { padding: 4px 8px; border: 1px solid #999; }
.row a.first { order: -1; }
</style>
<div class="row" id="row">
<a href="#a" id="a">Second on screen</a>
<a href="#b" id="b">Third on screen</a>
<a href="#c" id="c" class="first">First on screen</a>
</div>Run in Chrome 156 (headless) as a page; the snippet is wrapped in a minimal HTML document with doctype, charset and viewport meta tag. Two full runs gave identical results, and the measured values in the answer come from them.
Key points
- order sorts items by value; default is 0.
- Ties keep the HTML order.
- Only the visual order changes; DOM order stays.
- Focus and screen readers follow the DOM order.
- row-reverse and column-reverse have the same problem.
Common mistakes
- Using order or row-reverse to restructure the page and ignoring that tab order stays in the DOM order.
- Assuming screen readers read the visual order.
- Using large order values on many items, which makes the layout hard to follow in the code.
Follow-ups
- What is the default order value, and how are ties handled?
- How do row-reverse and column-reverse relate to this issue?
Tips
- Say that order is visual only and the DOM order drives focus and reading.
- Give a safe use and an unsafe use.