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.
Theory in plain words
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
The label is linked with htmlFor, the invalid state is announced with aria-invalid and the message with role="alert".
- Use
htmlFor(notfor) to connect labels in JSX. - Give images a meaningful
alttext, oralt=""if they are decoration. - After a route change, move focus to the main heading so screen readers notice the new page.
- Test with the keyboard only, and with the Lighthouse and axe browser tools.
Quick quiz
1. Which JSX attribute connects a label to an input?
for is a reserved word in JS.
2. Best element for a clickable action?
Buttons have keyboard and screen reader support built in.
3. What is alt="" for?
Screen readers skip them.
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.