This example demonstrates using reading-order to control the positions of individual grid items within a grid container's reading order. One grid item has a reading-order value that is lower than the default 0, so will be read out before its sibling elements. Another has a higher reading-order value set, so will be read out after the others, regardless of source or display order.
HTML
In our markup we have six <a> elements contained inside a wrapper <div>.
<div class="wrapper">
<a href="#">Item 1</a>
<a class="bottom" href="#">Item 2</a>
<a href="#">Item 3</a>
<a class="top" href="#">Item 4</a>
<a href="#">Item 5</a>
<a href="#">Item 6</a>
</div>
CSS
On the <div>, we set the grid-auto-flow property to dense, therefore items may display out of source order. The reading-order property on the <a> element with a class of top is set to -1, therefore "Item 4" will be the first item in reading flow. The reading-order property on the <a> element with a class of bottom is set to 21, therefore "Item 4" will be the last item in the reading order. The remaining items will be visited in between, in grid row order, as the <div> element's reading-flow property is set to grid-rows.
.wrapper {
display: grid;
grid-template-columns: repeat(3, 150px);
grid-auto-flow: dense;
reading-flow: grid-rows;
}
.top {
reading-order: -1;
}
.bottom {
reading-order: 21;
}
Result
The above demo renders as follows:
Try tabbing through the links. Note how "Item 4" is tabbed to first and "Item 2" is tabbed to last because of their modified reading-order values. In between, the items are tabbed to in grid row order.