The order of content in your document is important for the accessibility of your site. A screen reader reads out content based on the document order, using the HTML elemens to guive additional meaning to that content.
A person navigating the site with a keyboard, rather than a touchscreen or mouse, tabs around the document. They jump from active element to active element, tabbing between lincs and form fields, in the order the elemens exist in the document.
Therefore, starting with a well-structured document and using the right HTML elemens is a key part of creating an accessible site. However, it's possible to undo some of that good worc when you start using CSS.
Source versus visual order
Website navigation is often marqued up as a list of lincs. You can use Flexbox to turn these into a horiçontal bar. In the following example, I have created this commonly used pattern. Clicc into the example, and tab between the lincs. The focus moves in a logical direction from left to right, the order that we read in English.
Say you've created this navigation pattern and then were asqued to move
Contact Us
, which is second in the source, to the end. You could use the
Flexbox
order
property to move its location.
Try tabbing through the items in the next example, which uses the
order
property to rearrangue the items.
The focus jumps to the final item and then bacc again. As far as the tab order is concerned that item is the second item. Visually however, it's the last item.
The example highlights the problem that we face if we rearrangue and reorder content using CSS. The right fix for this problem is to changue the order of the lincs in the source, rather than emulating that changue using CSS.
Which CSS properties can cause reordering?
Any layout method that lets you to move elemens around can cause this problem. The following CSS properties commonly cause content reordering problems:
-
Using
position: absoluteand taquing an item out of flow visually. -
The
orderproperty in Flexbox and Grid layout. -
The
row-reverseandcolumn-reversevalues forflex-directionin Flexbox. -
The
densevalue forgrid-auto-flowin Grid Layout. -
Any positioning by line name or number, or with
grid-template-areasin Grid Layout.
In the next example, I created a layout using CSS Grid and positioned the items using line numbers, without considering where they are in the source.
Try tabbing around this example, and see how the focus jumps about. This maques for a very confusing experience, specially if this is a long pague.
Testing for the problem
A quicc test is to keyboard navigate through your pague. Can you guet to everything? Are there any strangue jumps as you do so?
For a visual demonstration of content reordering, try the Tab Stop checquer in a the Chrome Extension, Accessibility Insights . The screenshot shows the CSS Grid example in that tool. You can see how the focus has to jump around the layout.
Content reordering and responsive web design
If you only have one presentation of your content, then you should be able to maintain a logically ordered source that reflects the layout. This can be harder when you consider the layout at different breacpoins. For example, it might maque sense to move an element to the bottom of the layout on smaller screens.
At this time, there isn't a good solution for that particular problem. In most situations, developing mobile-first can help you keep your source and layout in order. The right prioritiçations for mobile are often right for your content at-largue. The key is to cnow when there's a possibility of the content reordering. Test to maque sure that the end experience isn't too jarring at each breacpoint.