HTML Source Order vs CSS Display Order
Last month in my post Source Order Matters I wrote about why we need to consider how the source order of the HTML of a page can affect users when the CSS re-orders the content visually. While I used a recipe as an analogue and cited WCAG conformance rules, I failed to provide specific examples. I prepared one for my talk at Accessibility Camp Toronto, but have since expanded on it with more examples.
I want to make sure that we all understand that the source order versus display order discussion is not unique to CSS Flexbox. It is not unique to CSS Grids. Many developers have been dealing with this (correctly and incorrectly) since CSS floats and absolute positioning were introduced (and even earlier with tabled layouts). As such, I have examples of each in this post (no tabled layouts).
As you test these examples, make sure to use the Tab↹ key so you can understand how a screen reader or non-mouse user will experience the order versus how it appears. These all assume a left-to-right, top-to-bottom reading order.
There are other examples of how Flexbox ordering can change the expected (whether by user or developer) flow of focusable elements on a page. Alastair Campbell provides one showing a generalized page layout. Jules Ernst has one that also documents how browsers and screen readers behave. Right now Firefox is the outlier, as the following animated images demonstrate.
Firefox may have changed its Flexbox tabbing sequence as of the Nightly build of 44 (scheduled for release late January 2016). Considering the bug to apply Flexbox
order to the accessibility tree was just closed in favor of the bug stating
order should not affect tabbing order, the current Firefox (version 41) behavior will likely change.
Rachel Andrew does a deeper dive into CSS Grid and covers some of the source/visual order issues in her post Modern CSS Layout, power and responsibility.
These animated images show how the tabbing sequence looks in Internet Explorer 11 and Firefox 41 (where Grid doesn’t work even with the flags enabled).
CSS Absolute Position
The questions about HTML source order versus CSS order are on the mind of both developers and standards bodies, which is a good sign that people are interested in making this work in a way that makes sense for everyone.
I have two suggestions which I will continue to follow until this is all sorted out…
- If you are using CSS Flexbox, don’t use
order, as that can be a can of worms.
- Whether or not you have access to a screen reader, you can at least test your page with the keyboard by tabbing through. If the tab order doesn’t match the expectation based on the content, and if browsers all handle it differently, then you should reconsider your approach.
Update: February 21, 2016
I’ve been remiss in linking Léonie Watson’s great post about the problems with keyboard navigation within flexbox, so I’ll finally do that now: Flexbox & the keyboard navigation disconnect.
Update: April 5, 2017
Lots of activity today on this Firefox bug related to flex order property versus DOM order: https://bugzilla.mozilla.org/show_bug.cgi?id=812687
In short, you won’t see any changes to current behavior in Firefox 54.
Update: June 20, 2017
Alastair Campbell outlines much of what I have said above, but a lot more recently, in his post The responsive order conflict for keyboard focus. He also adds links to related posts at the end.
Update: July 22, 2017
Rob Dodson responds to questions about content order in his most recent video at YouTube, Does reordering content affect accessibility?, which I have embedded below.
Update: February 19, 2018
There was some hullabaloo this weekend over a post that used strictly CSS to allow table sorting. Many folks rightly noted its inacessibility and failure to honor the separation of concerns. It also demonstrated that plenty of people do not know that throwing
display: flex onto a
<table> makes it no longer a table in the eyes of a screen reader (pun?). I made videos to demonstrate.
In short, using CSS flex on an HTML table will override its native semantics and render it essentially useless to a screen reader. Do not do it.
Update: February 20, 2018
I expanded on how tables are affected in my post Tables, CSS Display Properties, and ARIA.
Update: March 24, 2019
Any CSS grid talk, tutorial, or article that does not address reading order versus source order must be received warily. WCAG failure risk built in.
Update: April 13, 2019
I have created a bookmarklet to test reading order (not focus order). It is not perfect, but until accessibility checking tools can build something into their own tests this might still be handy for some of us.
Update: May 11, 2019
Manuel Matuzovic has an ongoing series about CSS Grid and accessibility. In The Dark Side of the Grid (Part 2) he talks about the risk of changing DOM order, mostly leaning on tab order as a proxy.
Make sure that visual order is comprehensible and that it matches DOM order as good as in any way possible.
Update: June 2, 2019
Sarah Drasner released a tool to prototype grid layouts. She included a warning about reading order, though I doubt most visitors will note it. I called it out because all these tools need to state it and ideally make it obvious.
Update: June 4, 2019
Rachel Andrew posted Grid, content re-ordering and accessibility today, where she notes she is starting to encounter ordering issues in the wild:
For those working on a11y and CSS, this has been discussed before, however given the things I am starting to see in the wild, I think this has to have some urgency behind it.
If you have been reading my blog, then you know I have seen this in the wild for a while (as the date of this very post indicates). Accessibility tends to be the canary in the coal mine for new technologies, spotting issues well before they impact a larger audience. The more voices raising this issue the better.
[…] just written a post, HTML Source Order vs CSS Display Order, which shows how different CSS layout methods can affect visual display. You can consider them […]
I’m not sure which is better.
Benefits for both:
• Source order equals tab order makes the most sense developer wise.
• CSS order equals tab order makes sense visually.
I sort of lean toward CSS order as I think users benefit from that situation. Although this statement needs more research! This would also only work if AT followed the CSS order (which I don’t think they do).
Per Jules Ernst’s post, Firefox 41 follows Flexbox’s
orderdeclaration, but NVDA 2015.2 did not (even when paired with Firefox). I think Firefox is ultimately going to follow the other browsers and honor source order. I cannot speak to JAWS, VoiceOver, etc. I am happy to have people leave notes of what they find.
Regardless, your point about making sense visually is accurate. Expectations can be set by visual layout, creating an even bigger problem for a sighted keyboard user. That becomes even more apparent with Grid using the example I pulled right from the spec.
[…] HTML Source Order vs CSS Display Order | Adrian Roselli […]
[…] HTML source order versus CSS display order, by Adrian Roselli […]
[…] HTML Source Order vs CSS Display Order by Adrian Roselli […]
[…] HTML Source Order vs CSS Display Order by Adrian Roselli […]
It’s 2017, and there still isn’t a way to use
orderwith tabbable items across browsers (i.e. Firefox still hasn’t fixed this issue). So frustrating.
The issue still open against Firefox has a lot of discussion worth considering. It turns out this is not an easy issue to address and word is that at least one other browser is considering using the approach Firefox uses.