Reading Order Properties in CSS

The proposed reading-flow and reading-order properties let authors define the source order of HTML elements in the DOM tree — effectively controlling how accessibility tools determine element order. Their main purpose is aligning the focus order of focusable elements with the visual order, as WCAG 2.2 requires. Currently they work only in Chrome 137 and above.

Container-Level Control with reading-flow

reading-flow sets the source order of elements inside flex, grid, or block layouts, helping accessibility tools deliver the correct focus order. The default is normal; the other values are flex-visual, flex-flow, grid-rows, grid-columns, grid-order, and source-order.

Flex Values

Consider five links in a flex row read left-to-right. Applying flex-direction: row-reverse displays them 5-4-3-2-1, yet tabbing still starts at 1 — visually wrong for a left-to-right reader. Adding reading-flow: flex-visual makes the focus order 5-4-3-2-1 as well, matching the visual order. (Reading direction itself can be changed with the direction property.)

<div>
  <a>1</a>
  <a>2</a>
  <a>3</a>
  <a>4</a>
  <a>5</a>
</div>
div {
  display: flex;
  flex-direction: row-reverse;
  reading-flow: flex-visual;
}

reading-flow: flex-flow restores default flex behavior. It resembles normal, except the container remains a reading flow container — a prerequisite for reading-order.

Grid Values

Grid items can be jumbled so that focus order scatters. reading-flow: grid-rows establishes a row-by-row focus order:

<div>
  <a>1</a>
  <a>2</a>
  <a>3</a>
  <a>4</a>
  <a>5</a>
  <a>6</a>
  <a>7</a>
  <a>8</a>
  <a>9</a>
  <a>10</a>
  <a>11</a>
  <a>12</a>
</div>
div {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-auto-rows: 100px;
  reading-flow: grid-rows;
  
  a:nth-child(2) {
    grid-row: 2 / 4;
    grid-column: 3;
  }

  a:nth-child(5) {
    grid-row: 1 / 3;
    grid-column: 1 / 3;
  }
}

Likewise, reading-flow: grid-columns establishes a column-by-column focus order. reading-flow: grid-order gives the default, jumbled grid behavior and, like flex-flow, still leaves the container registered as a reading flow container for use with reading-order.

Source Order

reading-flow: source-order applies to flex, grid, and block containers, turning them into reading flow containers in which reading-order can be used. The source author notes it appears to make the flex-flow and grid-order values redundant.

Item-Level Control with reading-order

reading-order targets specific flex or grid items, or elements within a simple block container. It works much like the order property, and is comparable to tabindex. The container must have reading-flow set to any value other than normal.

Setting order on each flex item to a random number scrambles the visual order. Applying reading-order in exactly the same way, as in the demo below, controls focus order regardless of visual order:

div {
  display: flex;
  reading-flow: source-order; /* Anything but normal */

  /* Features at the end because of the higher values */
  a:nth-child(1) {
    /* Visual order */
    order: 567;
    /* Focus order */
    reading-order: 567;
  }

  a:nth-child(2) {
    order: 456;
    reading-order: 456;
  }

  a:nth-child(3) {
    order: 345;
    reading-order: 345;
  }

  a:nth-child(4) {
    order: 234;
    reading-order: 234;
  }

  /* Features at the beginning because of the lower values */
  a:nth-child(5) {
    order: -123;
    reading-order: -123;
  }
}

The numbers do not represent positions — order: 3 or reading-order: 3 does not make the element third. Lower numbers come earlier in the order, higher ones later. The default value is 0, and elements sharing a value follow source order.

In a worked example, the first of five flex items carries order: -1 (lowest value), and the last carries order: 1 (highest). Undeclared items default to order: 0 and order by source, sitting between the two. The same concept applies to reading-order, which in that example mirrors order:

div {
  display: flex;
  reading-flow: source-order;

  a:nth-child(1) {
    order: 1;
    reading-order: 1;
  }

  a:nth-child(5) {
    order: -1;
    reading-order: -1;
  }
}

Reversed flex directions introduce a subtlety: reading-order: -1 still pulls an item to the start of the focus order, while order: -1 pushes it to the end of the (reversed) visual order — there, order: 1 is what's needed, counterintuitive as it seems:

div {
  display: flex;
  flex-direction: row-reverse;
  reading-flow: source-order;

  a:nth-child(5) {
    /* Because of row-reverse, this actually makes it first */
    order: 1;
    /* However, this behavior doesn’t apply to reading-order */
    reading-order: -1;
  }
}

reading-order overrides reading-flow. Any declaration that actually changes the reading flow — flex-visual, grid-rows, grid-columns — is overridden by reading-order, which can be thought of as applied afterwards.

Block Layouts and tabindex

Avoiding flexbox or grid rules out the flex and grid values of reading-flow, but reading-flow: source-order can still be set on a block element and the focus order managed with reading-order.

The two mechanisms are not equivalent. Negative tabindex values make targets unfocusable, and values besides 0 and -1 aren't recommended, whereas reading-order accepts any number because it is only contextual to its reading flow container. In testing, reading-order appeared to override tabindex. The source author's suggestion going forward: use tabindex (specifically tabindex="-1") only to remove targets from the focus order — disabled suits others better — and reading-order for everything else.

The Broader Picture

Defining reading order is useful, and it finally allows the order property to be used as intended. Until browser support extends beyond Chrome 137+, order has been of limited value because focus order could not be made to match visual order.