A solution for the visual and source order disconnect

A presentation at axe-con in February 2025 in by Rachel Andrew

Slide 1

Slide 1

Layout and reading order

Slide 2

Slide 2

Content lead for Chrome Developer Relations Rachel Andrew CSS WG member rachelandrew.co.uk

Slide 3

Slide 3

24ways.org/2012/css3-grid-layout

Slide 4

Slide 4

CSS Grid, Baseline Widely available since January 2023

Slide 5

Slide 5

Slide from 2015 CSS Day grid talk

Slide 6

Slide 6

“You never know how tall anything is on the web” Me … for most of my web development career.

Slide 7

Slide 7

Slide 8

Slide 8

Slide 9

Slide 9

Slide 10

Slide 10

web.dev/articles/css-subgrid

Slide 11

Slide 11

reading-flow A missing puzzle piece that can prevent problems and unlock capabilities.

Slide 12

Slide 12

.grid a:nth-child(3) { grid-column: span 3; grid-row: span 3; } .grid { display: grid; grid-auto-flow: dense; grid-template-columns: repeat(4,1fr); }

Slide 13

Slide 13

Slide 14

Slide 14

Here’s a cool thing Please don’t use it.

Slide 15

Slide 15

CSS Grid Level 1 Correct source order is important for speech, for sequential navigation (such as keyboard navigation), and non-CSS UAs such as search engines, tactile browsers, etc. Grid placement only affects the visual presentation! This allows authors to optimize the document source for non-CSS/nonvisual interaction modes, and use grid placement techniques to further manipulate the visual presentation so as to leave that source order intact.

Slide 16

Slide 16

Separating content from presentation Something we’ve tried to do since the early days of CSS layout.

Slide 17

Slide 17

https://rachelandrew.co.uk/archives/2019/06/04/grid-content-re-ordering-and-accessibility/

Slide 18

Slide 18

https://github.com/w3c/csswg-drafts/issues/5675

Slide 19

Slide 19

https://tink.uk/flexbox-the-keyboard-navigation-disconnect/

Slide 20

Slide 20

reading-flow CSS Display Level 4

Slide 21

Slide 21

Can we just opt into the order that flex or grid items are laid out?

Slide 22

Slide 22

Reading or visual order is subjective

Slide 23

Slide 23

flex-direction: row-reverse

Slide 24

Slide 24

In most cases DOM order is what you want No universal switch to let developers forget about source order.

Slide 25

Slide 25

Scoped to particular layout methods We’re not trying to do this on block layout.

Slide 26

Slide 26

reading-flow: normal Follow the order of items in the DOM. The initial value.

Slide 27

Slide 27

.flex { display: flex; flex-direction: row-reverse; }

Slide 28

Slide 28

normal flex-flow flex-visual grid-rows grid-columns grid-order Values for reading-flow

Slide 29

Slide 29

reading-flow: flex-visual Follow the visual layout, taking writing mode and direction into account.

Slide 30

Slide 30

.flex { display: flex; flex-direction: row-reverse; reading-flow: flex-visual; }

Slide 31

Slide 31

reading-flow: flex-flow Follow the flow order.

Slide 32

Slide 32

.flex { display: flex; flex-direction: row-reverse; reading-flow: flex-flow; }

Slide 33

Slide 33

Adding the order property The reading flow now takes into account the modification made by order.

Slide 34

Slide 34

.flex a:nth-child(3) { order: -1; } .flex { display: flex; flex-direction: row-reverse; reading-flow: normal; }

Slide 35

Slide 35

.flex a:nth-child(3) { order: -1; } .flex { display: flex; flex-direction: row-reverse; reading-flow: flex-visual; }

Slide 36

Slide 36

.flex a:nth-child(3) { order: -1; } .flex { display: flex; flex-direction: row-reverse; reading-flow: flex-flow; }

Slide 37

Slide 37

Grid and reading flow Automatic layout—grid-auto-flow: dense

Slide 38

Slide 38

Slide 39

Slide 39

Slide 40

Slide 40

reading-flow: grid-rows Follow the reading order by row.

Slide 41

Slide 41

.grid a:nth-child(3) { grid-column: span 3; grid-row: span 3; } .grid { display: grid; grid-auto-flow: dense; grid-template-columns: repeat(4,1fr); reading-flow: grid-rows; }

Slide 42

Slide 42

reading-flow: grid-columns Follow the reading order by column.

Slide 43

Slide 43

Slide 44

Slide 44

.grid a:nth-child(2) { grid-column: span 3; grid-row: span 3; } .grid { display: grid; grid-auto-flow: column dense; grid-template-columns: repeat(5,1fr); reading-flow: grid-columns; }

Slide 45

Slide 45

Grid and reading flow Line-based placement, grid-template-areas

Slide 46

Slide 46

.grid { display: grid; grid-template-columns: repeat(5,1fr); grid-template-areas: “b b b b b” “d d f f f” “d d e c a”; }

Slide 47

Slide 47

.grid { display: grid; grid-template-columns: repeat(5,1fr); grid-template-areas: “b b b b b” “d d f f f” “d d e c a”; reading-flow: grid-rows; }

Slide 48

Slide 48

reading-flow: grid-order As normal, but take the order property into account.

Slide 49

Slide 49

Slide 50

Slide 50

The reading-order property For the children of a reading flow container.

Slide 51

Slide 51

Slide 52

Slide 52

.grid a:nth-child(3) { grid-column: span 3; grid-row: span 3; } .grid { display: grid; grid-auto-flow: dense; grid-template-columns: repeat(4,1fr); reading-flow: grid-rows; } .grid a:nth-child(5) { grid-column: 4; grid-row: 1; grid-order: -1; }

Slide 53

Slide 53

Source order is important Never use reading-flow to avoid the work of updating your HTML.

Slide 54

Slide 54

Create a sensible document Then consider small tweaks to optimize the reading experience at different breakpoints.

Slide 55

Slide 55

Try it out in Chrome Canary https://chrome.dev/reading-flow-examples

Slide 56

Slide 56

Thank you Rachel Andrew https://noti.st/rachelandrew/mqtF84/