Skip to content

React Accessibility Explained — Building Inclusive Web Apps

DodaTech Updated 2026-06-28 1 min read

In this tutorial, you will learn about React Accessibility Explained. We cover key concepts, practical examples, and best practices to help you master this topic.

React accessibility (a11y) ensures web applications are usable by people with disabilities through semantic HTML, ARIA attributes, keyboard navigation, and screen reader support.

What You'll Learn

  • Why accessibility matters
  • How to use ARIA attributes in React
  • How to manage focus and keyboard navigation
  • How to test accessibility
  • Common accessibility patterns

Why It Matters

Accessibility is both an ethical responsibility and legal requirement in many jurisdictions. React provides built-in support for accessible HTML and patterns for advanced scenarios.

import { useRef, useEffect } from "react";

function Modal({ isOpen, onClose, title, children }) {
  const modalRef = useRef(null);
  const previousFocus = useRef(null);

  useEffect(() => {
    if (isOpen) {
      previousFocus.current = document.activeElement;
      modalRef.current?.focus();
    } else {
      previousFocus.current?.focus();
    }
  }, [isOpen]);

  useEffect(() => {
    const handleEscape = (e) => { if (e.key === "Escape") onClose(); };
    document.addEventListener("keydown", handleEscape);
    return () => document.removeEventListener("keydown", handleEscape);
  }, [onClose]);

  if (!isOpen) return null;

  return (
    <div role="dialog" aria-modal="true" aria-labelledby="modal-title">
      <h2 id="modal-title">{title}</h2>
      {children}
      <button onClick={onClose} aria-label="Close modal">X</button>
    </div>
  );
}

Expected output: The modal traps focus, announces via aria-labelledby, closes on Escape, and restores focus when closed.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro