Important Update
The Guide Feature will be discontinued after December 15th, 2023. Until then, you can continue to access and refer to the existing guides.
Author avatar

Gaurav Singhal

How to Create Ordered Lists with HTML5 for Screen Readers

Gaurav Singhal

  • Jul 17, 2019
  • 8 Min read
  • Jul 17, 2019
  • 8 Min read
Web Development


Web accessibility is an important aspect to assure everyone can access the web impartially and on the same level. This means a website must also be usable and accessible by people with disabilities. When building React applications, it can be easy to forget about the accessibility of the application we are building. In this guide, we are going to converge on making the web favorable for people who are visually impaired.

Screen Readers

First, let’s explore a brief explanation of screen readers so that we can recognize the needs of our users.

"Screen readers take the semantic information from your elements and produce an alternative, spoken UI, for a user with visual impairments."

By default, HTML5 lists have the right semantics for screen readers to announce them as lists. But while building web applications, due to one or more reasons, we might not be able to use the native HTML5 lists. Well, that's where ARIA roles come to the rescue.

Accessibility Rich Internet Applications (ARIA)

ARIA stands for Accessibility Rich Internet Applications; it's a specification that contains a set of attributes that you can add to an element. It can manipulate the accessibility tree and add in additional semantics. An accessibility tree is simply a subset of the DOM tree. The browser removes all the presentation elements and modifies the DOM tree so that it can be suitable for assistive technologies like screen readers. This remodeled DOM tree is called as the accessibility tree.

It is best to use the native HTML elements to get the right semantics, but sometimes when working on third-party code, or while developing complex UI, you might have to build custom elements. We can use ARIA attributes to give these custom elements the right semantics so that they can be announced rightly by screen readers.

Some of the information that the screen reader announces about an ordered or unordered list include:

  • The size of the list
  • The position of each item in the list
  • When the user has left one list and has entered another

While it depends on the individual screen reader, the above points are the most common.

Example (Finally! Some Code)

Let's begin with how we can use ARIA attributes to make our document accessible.

An HTML element can have a role attribute of list or listitem, so that it can be interpreted as a list by screen readers. Ordered or unordered list, it's all the same for ARIA. When traversing native list elements, the screen readers announce the number before the start of an ordered list item and "bullet" before the start of an unordered list item but it never announces the list as ordered or unordered; it only gets becomes while traversing the list.

1<div role="list">
2    <div role="listitem">HTML</div>
3    <div role="listitem">CSS</div>
4    <div role="listitem">JavsScript</div>

In the above snippet, div tags are used to be represented as lists and list items. The screen readers will interpret and announce it as "List with three items" and at the end of each list item, it will announce "listitem". But this isn't much help to make the user understand whether it's an ordered or unordered list.

To announce a number before each list element, we can use the aria-label attribute.

1<div role="list">
2    <div role="listitem"><span aria-label="1"></span> HTML</div>
3    <div role="listitem"><span aria-label="2"></span> CSS</div>
4    <div role="listitem"><span aria-label="3"></span> JavaScript</div>

I'm using a ChromeVox screen reader for the demo; there are many screen readers out there, some of which will be linked to at the end of this article.

It can be tempting to use role on every element but, as I mentioned earlier, it's highly recommended to use the native elements that have the right semantics to build a list (because with great powers come significant responsibilities). Having said that, the role should not be used on native elements since they have implicit semantics. For example, ol or ul tags need not have a role=list attribute, and likewise, li tags need not have role=listitem.

Accessible Lists in React

But how would ARIA attributes fit in with React Application, more precisely in JSX?

JSX compiles down to HTML, and it is possible due to ineffective methods JSX may compile to non-semantic HTML and we all know how difficult it is to interpret for screen readers. This ends up producing inaccessible web apps.

For example:

1render() {
2    return (
3        <div>
4            { => <li>{f}</li>)}
5            <li> Ember </li>
6        </div>
7    )

Writing such JSX will result in non-semantic HTML. The above code, when compiled, will result in the following:

2    ...
3    <div>
4        <li>...</li>
5        <li> Ember </li>
6    </div>

Screen readers wouldn't announce the list in this case and will only list individual list items, which can be confusing to the end-user.

The correct way to wrap a component's children is by using React Fragments.

React Fragment

"A common pattern in React is for a component to return multiple elements. Fragments let you group a list of children without adding extra nodes to the DOM."

Using the <React.Fragment> component, we can add a parent element to JSX elements without introducing an extra node in the DOM (Document Object Model), which means the <React.Fragment> outputs no HTML Element.

There is also a shorthand version of React Fragment - <>...</>

Complete Code

1import React, { Component } from "react";
2import ReactDOM from "react-dom";
4class JSFrameworks extends Component {
5  constructor(props) {
6    super(props);
7    this.state = {
8      frameworks: ['React', 'Angular', 'Vue']
9    }
10  }
12  render() {
13    return (
14      <>
15        { => <li>{f}</li>)}
16        <li>Ember</li>
17      </>
18    )
19  }
22class App extends Component {
23  constructor(props) {
24    super(props);
25    this.state = {
26      listItems: ['HTML', 'CSS', 'JavaScript']
27    };
28  }
30  render() {
31    return (
32      <div className="App">
33        <h1> Inaccessible Lists </h1>
34        <ol>
35          { => <li>{item}</li>)}
36          <ol type='i'>
37            <JSFrameworks />
38          </ol>
39        </ol>
40      </div>
41    );
42  }
45const rootElement = document.getElementById("root");
46ReactDOM.render(<App />, rootElement);

ARIA in React Apps

React fully supports the use of ARIA-* attributes in JSX. We don't need to camel-case the attribute names in case of the ARIA(even React is afraid to mess with ARIA - sorry no more Arya jokes I promise).

1render() {
2    return (
3        <div role="list">
4            <div role="listitem"><span aria-label="1"></span> HTML</div>
5            <div role="listitem"><span aria-label="2"></span> CSS</div>
6            <div role="listitem"><span aria-label="3"></span> JavaScript</div>
7        </div>
8    );


I hope you are now convinced of how important it is to build accessible web apps and can take some notes from this guide. Now, get out of here and start building stuff. Cheers and Happy Coding.

Popular Screen Readers