CSS Flexbox order: visual order and keyboard navigation
In Flexbox, order lays out items from the smallest integer to the largest. The initial value is 0, and ties follow HTML order. The property by itself does not change the document structure or default Tab sequence, so put steps and controls in a logical order in the HTML.
How smaller integers come first
.item { order: 0; }
.featured { order: -1; }
Set the integer on a flex item whose parent uses display: flex or inline-flex. Negative integers are valid. A value like 1.5 or 1px is invalid. Setting order on a child of a normal block does not reorder it within that block. See CSS Display · order.
order: 1 does not mean “put this in the first slot.” With A, B, C in the HTML, assigning 1 to A alone makes the row appear as B, C, A. B and C retain the default value of 0.
Try the example with visual and Tab order
Save the example as flex-order.html and open it. It needs no external files or JavaScript. Both rows contain A, B, C in HTML. The first row keeps the default 0. The second assigns 2, 3, and 1 to A, B, and C, so the displayed order from the left is C, A, B.
<!doctype html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Flexbox order and document order</title>
<style>
body { margin: 20px; font: 16px/1.6 system-ui, sans-serif; color: #203348; }
* { box-sizing: border-box; }
h1 { font-size: 24px; } h2 { margin: 18px 0 6px; font-size: 18px; }
.row { display: flex; gap: 8px; max-width: 360px; padding: 12px;
border: 1px solid #7795a3; background: #edf5f7; }
.item { flex: 1 1 0; min-width: 0; min-height: 60px; padding: 8px;
border: 0; border-radius: 4px; background: #176f80; color: white; font: inherit; }
.item:focus-visible { outline: 3px solid #b75c00; outline-offset: 2px; }
.changed .a { order: 2; }
.changed .b { order: 3; }
.changed .c { order: 1; }
</style>
</head>
<body>
<h1>Compare order values</h1>
<h2 id="order-original">Default: all zero</h2>
<div class="row original" role="group" aria-labelledby="order-original">
<button class="item a" type="button">A</button>
<button class="item b" type="button">B</button>
<button class="item c" type="button">C</button>
</div>
<h2 id="order-changed">A: 2 · B: 3 · C: 1</h2>
<div class="row changed" role="group" aria-labelledby="order-changed">
<button class="item a" type="button">A</button>
<button class="item b" type="button">B</button>
<button class="item c" type="button">C</button>
</div>
<p>Use Tab to compare screen position and focus order. These buttons have no other function.</p>
</body>
</html>
In ordinary Tab navigation, focus still goes through A, B, C in the second row. In terms of screen position it moves middle → right → left. The orange outline shows the focused button. The buttons exist for the exercise and have no action attached. See HTML Standard · Sequential focus navigation.
Test negative values, ties, and row-reverse
Replace the second row’s three order rules with the following. C is first because its value is -1. A and B tie at 0 and keep their HTML order. Setting all three to 0 restores A, B, C.
.changed .a { order: 0; }
.changed .b { order: 0; }
.changed .c { order: -1; }
Restore 2, 3, and 1 and change B alone from 3 to 2. C still comes first, and A precedes B because their values tie. Now restore 2, 3, and 1 again and add row-reverse as shown. The order from the start of the main axis is still C, A, B. That axis starts at the right, so from the left you see B, A, C. Remove the direction override afterward. See CSS Flexbox · flex-direction.
.changed {
flex-direction: row-reverse;
}
Use order without disrupting the document sequence
Keep the HTML sequence meaningful for steps, forms, or questions and answers. Rearranging content only visually and trying to compensate with positive tabindex values makes the whole page’s navigation order harder to manage as controls change.
CSS Display Level 4 · Reading Flow defines a separate reading-flow feature for adjusting sequential navigation where supported. This example leaves it unset. If your site does use it, check navigation in that context and keep a logical sequence in the HTML as well.
If the item does not move, check which element is actually the direct flex item. Styling an inner descendant does not reorder its outer wrapper alongside the siblings. Then check the parent’s display, each item’s computed order, and the flex-direction and writing direction that determine where the row starts.




