Responsive UI - modify reading order in screen readers?

Viewed 2585

I have a responsive layout that must be accessible for screen readers. The issue is around the order of buttons on desktop vs mobile. On desktop the button order is

Cancel - Remind Me Later - Learn More

...and the screen reader reads left to right. However on mobile the button order is vertically stacked and is ordered as the reverse of the desktop:

Learn more Remind me later Cancel

The problem is the screen reader still reads as if user was in desktop mode - the visual order no longer matches.

Is there a way for the screen reader to change the reading order depending on the viewport?

3 Answers

In general, screen reading software ignores CSS (*). The order of your DOM is the order the screen reader will read it. Even if you used tabindex, that will only control the order of tabbing through the interface. If you use CSS to reposition elements, whether through flexbox or grid or float, the screen reading software will ignore that.

A screen reader user can simply walk the DOM (**) by using the up/down arrow keys. (** The user is not really walking the DOM but rather the accessibility tree, but it's similar to the DOM. Not every element in the DOM will be on the accessibility tree, but it's a similar analogy).

So, the only way to "control" the order that a screen reader hears the elements is by modifying the order of the elements in your DOM.

(*) (If you have a :before or :after pseudo-element with a content property, that property will be read by a screen reader as noted in step 2F of the "Accessible Name and Description Computation")

This is a common issue and there are a few solutions you can do. Without knowing much about your codebase, here are a few suggestions for you:

  1. Not knowing how complex your markup is, you could provide a version of the form elements that are only visible on small screens. That way you can explicitly control the accessibility tree structure.

  2. Another option, you can use CSS (flexbox or grid) to reposition the buttons based your media query for small screens.

  3. While this would work, I would not advice using "tabindex="1", "2", "3" "..." to control tab order seeing as how your UI is not rendering in the correct order anyway.

Hope this helps. Good luck with your project.

Is there a way for the screen reader to change the reading order depending on the viewport?

One solution is to have two sets of the same menu and use your media queries to use one or the other

<div class="desktop">Cancel - Remind Me Later - Learn More</div>
<div class="mobile">
Learn more
Remind me later
Cancel
</div>

CSS:

.mobile {display:none}
@media screen and (max-width: 600px) {
   .desktop {display:none}
   .mobile {display:block}
}

This way, you will be free to let the DOM order match the visual order.

Related