Home / Learn React / Accessibility in React

Accessibility in React

Accessible apps work for everyone: keyboard users, screen readers and people with low vision. Good HTML already gives you most of it.

In shortUse the right element (button, not div), label every input, keep focus visible and manage focus for dialogs and route changes.

Theory in plain words

Same look, different accessdiv onClickNot focusableNo keyboard EnterAnnounced as textbutton onClickFocusableEnter and Space workAnnounced as button
Same look, different access

What it is

Accessibility (a11y) is making sure people with disabilities can use your app. It relies on semantic elements, labels, keyboard support and sufficient colour contrast.

Why we use it

About one in six people live with a disability, and many laws require accessible sites. Accessible code is also easier to test and better for SEO.

How it works

Browsers expose elements to assistive technology as an accessibility tree. A real <button> is focusable and announced as a button, a clickable <div> is not.

Where it is used

  • Every public website and web app
Labels, errors and live regionsTry it Yourself

The label is linked with htmlFor, the invalid state is announced with aria-invalid and the message with role="alert".

Quick quiz

1. Which JSX attribute connects a label to an input?

2. Best element for a clickable action?

3. What is alt="" for?

Common questions

Which JSX attribute connects a label to an input?

htmlFor. for is a reserved word in JS.

Best element for a clickable action?

button. Buttons have keyboard and screen reader support built in.

What is alt="" for?

Decorative images. Screen readers skip them.