Take this:
<ol>
<li>Get hungry</li>
<li>Order pizza</li>
<li>Eat pizza</li>
</ol>
That HTML ends up in the DOM that way (and thus how it is is exposed to assistive technology), and by default, those list items are also visually shown in that order. In most layout situations, the visual order will match that DOM order. Do nothing, and the list items will flow in the block direction of the document. Apply flexbox, and it will flow in the inline direction of the document.
But flexbox and grid also allow you to muck it up. Now take this:
ol {
display: flex;
flex-direction: row-reverse;
}
In this case, the DOM order still makes sense, but the visual order is all wrong. It’s not just row-reverse
. There are a number of flexbox and grid properties that can get involved and confuse things: the order
property, flowing items into columns instead of rows, and positioning items specifically in unusual orders, among others. Even absolute positioning could cause the same trouble.
Manuel Matuzovic says:
If the visual order and the DOM order don’t match, it can irritate and confuse users up to a point where the experience is so bad that the site is unusable.
Rachel Andrew highlights this issue (including things we’ve published) as a big issue, and hopes we can get tools at the CSS level to help.
I think this is something we sorely need to address at a CSS level. We need to provide a way to allow the tab and reading order to follow the visual order. Source order is a good default, if you are taking advantage of normal flow, a lot of the time following the source is exactly what you want. However not always, not at every breakpoint. If we don’t give people a solution for this, we will end up with a mess. We’ve given people these great tools, and now I feel as if I’m having to tell people not to use them.
You can use this to your advantage responsively, with the accessible DOM order being default for screen readers, SEO and mobile while wider screens can present either horizontally or vertically in columns depending on your content.
I detailed this in a CSS Trick post some 3 years back, it’s funny not much has changed and CSS Grid has provided some alternate options but no solution for this visual vs DOM order issue.
Currently, automated accessibility checkers only check tab order, not reading order, of flex and grid layouts. I have opened feature requests to show reading order, but in the meantime have made a bookmarklet to fill the gap until those exist: http://adrianroselli.com/2019/04/reading-order-bookmarklet.html
Say someone was going to set out to fix this… Baby thoughts:
tabindex
involved here? Could it cause harm from the HTML level no matter what? Maybe the CSS solution is something like moving tabindex to CSS?Agreed; this challenged is caused in CSS and should be fixed there (by authors).
tabindex
is not the same as reading order, so even iftabindex
was moved to CSS it would not address the problem; separately, movingtabindex
out of HTML will break every non-standard<div>
-as-clickable control (most frameworks and libraries).Firefox by default originally followed DOM order, but then a bug was filed and it was changed; IOW, browsers would need to all move on this along with managing author expectations;
Grid, flex, floats, absolute positioning. I started tracking this in a 2015 post with updates through this month.