visit
In this article, we explore what web accessibility is, how it intersects with ReactJs, and the core principles of web accessibility.
This article assumes that the reader knows Basic HTML, CSS, JavaScript, and ReactJs.
Perceivable: The content displayed on a website or webpage should be available for consumption for every kind of user. Overlooking this puts users with visual, auditory, or cognitive impairments at a great disadvantage. Some simple practices that will make your web content perceivable are:
Operable: Content on your website or web application should be easy to read, use, navigate, and interact with. This ensures inclusivity for users with motor or dexterity impairments. Some ways this can be implemented are:
Understandable: Text content occupies a large part of most websites, and making sure that text content on your website is understandable, identifiable, concise, and readable to the broadest audience possible is important. Some ways you achieve this are:
Robust: Content is said to be robust when it is compatible with a range of different web browsers, assistive technologies, and . Some ways to implement robust designs are:
WCAG 1.0: Consisted of 14 guidelines that serve as the principles of accessible design.
WCAG 2.0: This update came when mobile Internet devices were just becoming popular, making it difficult to predict what the future use of mobile devices would look like.
WCAG 2.1: Released in June 2018, it adds 17 new success criteria to version 2.0. These new guidelines are built around helping people who have low-level vision, cognitive disabilities, and learning disabilities. It also includes guidelines to assist in removing mobile technology barriers.
As of the time of writing this article, WCAG version 2.2 have not been released, but they have been said to include information about improving accessibility of mobile applications. You can learn more about these guidelines .
ReactJs has cemented itself as the go-to UI library for 40.6 percent of JavaScript developers worldwide (According to Statista, 2023). That said, with a large number of developers using the technology for websites globally, it becomes important for these websites to be accessible for all kinds of users.
So how exactly does React achieve this?
Utilizing semantic HTML elements in React components: Semantic HTML elements can be said to be the backbone of accessibility for any web application. Sometimes HTML semantics are broken when we group elements like lists (<ol>
, <ul>
, <table
) and HTML tables in <div>
elements. In cases like this, it would be best practice to make use of React Fragments. The code snippet below shows how to implement them.
import React, { Fragment } from 'react';
function ListItem({ item }) {
return (
<Fragment>
<dt>{item.term}</dt>
<dd>{item.description}</dd>
</Fragment>
);
}
function Glossary(props) {
return (
<dl>
{props.items.map(item => (
<ListItem item={item} key={item.id} />
))}
</dl>
);
}
Enabling keyboard navigation and focus management: Manage focus appropriately to ensure keyboard users can navigate through your application smoothly. You can use the ref
attribute to access DOM elements and apply focus programmatically. The tabIndex
attribute can also be used to control the order in which elements receive focus.
import React, { useEffect, useRef } from 'react';
function FocusableComponent() {
const myRef = useRef();
useEffect(() => {
myRef.current.focus();
}, []);
return (
<div tabIndex="0" ref={myRef}>
Focusable Element
</div>
);
}
export default FocusableComponent;
Providing alternative text for images and icons used in React components.
Implementing ARIA roles and attributes for enhanced accessibility: ARIA (Accessible Rich Internet Applications) attributes provide additional accessibility information to assistive technologies. For instance, you can use role
attributes to define the purpose of an element, such as a navigation menu or a button. Additionally, attributes like aria-label
, aria-describedby
, and aria-labelledby
can provide context and labels for screen readers.
import React from "react";
function myButton () {
return (
<button aria-label="Close" role="button" onClick={handleClose}>
<span aria-hidden="true">×</span>
</button>
)
}
Automated Accessibility Testing Tools:
Axe: Axe is a widely used accessibility testing tool that enables testers with little knowledge of accessibility to perform step-by-step manual accessibility testing. It can be integrated into your browser's developer tools or used as a standalone extension. To learn more about this tool, visit .
Lighthouse: Lighthouse is an integrated tool in Chrome DevTools that offers accessibility audits and then gives an accessibility score, among other performance checks. You can learn more about this tool
Manual Accessibility Testing: Performing manual testing operations on your application is essential for catching nuanced issues that automated tools might miss. Some manual testing techniques include:
Keyboard Testing: Navigate through your application using only the keyboard to ensure all interactive elements are reachable and usable.
Screen Reader Testing: Use screen reader software (e.g., VoiceOver, JAWS, NVDA) to experience your application as users with visual impairments would. Verify that information is conveyed accurately and interactions are meaningful.
Zoom and High Contrast Testing: Adjust your browser settings to simulate low vision conditions and test whether your application remains usable.
Focus Management Testing:
Semantic HTML and ARIA Testing:
Review your HTML structure and verify that you're using appropriate semantic elements (e.g., headings, lists) to convey content hierarchy.
Real User Testing: