Advertisement
Intermediate React, Accessibility (a11y) in React

How do ARIA attributes help improve accessibility in a React component?

Short answer

ARIA attributes give extra information to screen readers when plain HTML is not enough to describe what an element does. For example, aria label describes a button that only has an icon, and aria expanded tells a screen reader whether a menu is open or closed.

Save React mock interview
Advertisement
AModel answer
ARIA attributes give extra information to screen readers when plain HTML is not enough to describe what an element does. For example, aria label describes a button that only has an icon, and aria expanded tells a screen reader whether a menu is open or closed. ARIA should only be used when semantic HTML alone cannot express the meaning.
function MenuButton({ isOpen, onClick }) {
  return (
    <button aria-expanded={isOpen} aria-label="Open navigation menu" onClick={onClick}>
      <MenuIcon />
    </button>
  );
}
Real-world example
A shopping app adds aria expanded to its dropdown filter menu so screen reader users know whether the filter options are currently showing or hidden.
Likely follow-ups
  • When should you avoid using ARIA attributes instead of native HTML elements?
  • What is the difference between aria label and aria labelledby?
Related topics