Accessible Overflow
Tags: a11y
Published: 2021-07-08 05:49:43

---
title: Accessible Overflow
published: true
description: Little notes about the somehow inconsistent focusing and scrolling behavior of overflowing containers
canonical_url: https://marcus.io/blog/accessible-overflow
tags: a11y
cover_image: https://marcus.io/content/1-blog/20210607-accessible-overflow/overflow.jpg
---

One major tenet of web accessibility is that users have various strategies to operate your website. While still too many web developers aren't able to name input modes beyond pointer devices (mouse and touch), properly covering keyboard accessibility will get you the most bang for your buck. If you ensure that all the features of your site can be operated with a defined collection of keys (tab key, space bar, enter key, arrow keys, etc) you largely increased the likelihood that people with all kinds of strategies and assistive technologies are able to use the site you built.

## Rock'n'Scroll

"Navigating a website" can, of course, mean jumping from interactive control to interactive control but most forms of interactions come down to reading or passively experiencing your content. A central way to do that is of course scrolling. It's obvious that mouse owners can use the scrollbar or a particular mouse wheel and touch users drag the site up or down. But I think the strategy keyboard-only users employ for scrolling is known far beyond this user group: using your keyboard's arrow keys (or is it just me, especially when reading long texts on the Desktop?).

Anyway, arrow keys scroll the overall website, regardless of the focus's precise position, and sometimes, this is all you need. But what about particular containers that harbour content that is either horizontally or vertically too large for its parent? It is allowed to overflow, more often than not with the CSS `overflow: auto`. Alas, the situation around keyboard accessibility of these containers is patchy, and I only completly realized this _after_ a current customer project which had an overflowing container. So, what follows is my little research on the topic and the current state of overflow scrolling afairs (see original sources at the bottom of the article).

## Overflow and Focus

Firefox, for example, puts an overflowing container into the tab order, making it reachable and its content scrollable. Because it has no focus styles, it is not really obvious that it has focus, though, but web developers can at least write a CSS selector like `.my-overflowing-div:focus` to make its state more clear to friends of the Mozilla. However, the situation in Chrome, Chrome-based Edge and Safari is different. Without any changes in the HTML, overflowing content is not scrollable with the keyboard (unless, of course, there is an interactive element inside the container - but this scrolling doesn't uncover every part of the container).

> All interactive should be focusable
> <cite>[(Using WAI-ARIA)](https://www.w3.org/TR/wai-aria-1.0/usage#managingfocus_header)</cite>

## Ensuring a coherent experience across browsers

The Webkit and Blink team are aware of this topic insofar that issues related to that exist for 3 or 5 years, respectively ([Webkit Issue # 585413](https://bugs.webkit.org/show_bug.cgi?id=190870) and [Chrome's one even is on "Intent to ship" since 2.5 years](https://bugs.chromium.org/p/chromium/issues/detail?id=584618)). Unfortunately, there is nothing tangible beside the tickets, so web developers must apply a hack if they want to convey Firefox's behaviour to all browsers. This workaround, or "hack" as Adrian Roselli calls it, comes from Steve Faulkner and consists of three steps:
1. Add `tabindex="0"` to the overflowing container to make it baseline keyboard accessible.
2. Show this keyboard accessibility to users by applying custom focus styles: `.my-owerflowing-div:focus { outline: 2px solid; }` (if you want to be both future-proof when it comes to WCAG and an overall good web author citizen, [take care of focus style contrasts](https://www.w3.org/WAI/standards-guidelines/wcag/new-in-22/#2411-focus-appearance-minimum-aa)).
3. "Promote" the `<div>` to a landmark region by both applying `role="region"` **and** supplying an accessible name, by using `aria-label`, for example. By doing so, you provide much-needed context to screen reader users - because they suddenly discover a focussable element that is not interactive in the classic sense (like a link or button would be).

## Demos and Links

{% codepen https://codepen.io/stevef/pen/JGaoob %}

- [Steve Faulkner provided the code mentioned above combined into a CodePen](https://codepen.io/stevef/pen/JGaoob)
- More than five years ago, he published [Short note on improving usability of scrollable regions](https://www.tpgi.com/short-note-on-improving-usability-of-scrollable-regions/)
- As for every web accessibility topic, Adrian Roselli has a deep dive article: [Keyboard and Overflow](https://adrianroselli.com/2016/02/keyboard-and-overflow.html)