Autocomplete Accessibility Implementation
Making the autocomplete accessible with ARIA roles and screen reader support.
Autocomplete Accessibility Implementation
Making the autocomplete accessible ensures it works with screen readers and keyboard navigation.
ARIA Attributes
<div class="autocomplete" role="combobox" aria-expanded="false" aria-owns="suggestions"> <input type="text" id="searchInput" role="textbox" aria-autocomplete="list" aria-controls="suggestions" aria-activedescendant="" placeholder="Search..." /> <ul id="suggestions" role="listbox"></ul> </div>
Updating ARIA
// On show suggestions container.setAttribute("aria-expanded", "true"); // On hide suggestions container.setAttribute("aria-expanded", "false"); // On highlight change input.setAttribute("aria-activedescendant", `suggestion-${currentHighlight}`); // On each suggestion <li id="suggestion-0" role="option" aria-selected="false">...</li> // On highlight item.setAttribute("aria-selected", "true");
Key ARIA Attributes
role="combobox": the container is a combobox.aria-expanded: whether suggestions are visible.aria-autocomplete="list": the input autocompletes from a list.aria-controls: the ID of the suggestions list.aria-activedescendant: the ID of the currently highlighted suggestion.role="option": each suggestion is an option.aria-selected: whether a suggestion is highlighted.
The Takeaway
Accessible autocomplete: role="combobox", aria-expanded (visible/hidden), aria-autocomplete="list", aria-controls (suggestions ID), aria-activedescendant (highlighted suggestion ID), role="option" on each suggestion, aria-selected on highlighted. Update these via JavaScript on every interaction.
Add role='combobox' and aria-expanded on the container. role='textbox', aria-autocomplete='list', aria-controls, and aria-activedescendant on the input. role='option' and aria-selected on each suggestion. Update aria-expanded and aria-activedescendant via JavaScript.
role='combobox', aria-expanded (true/false), aria-autocomplete='list', aria-controls (suggestions list ID), aria-activedescendant (highlighted suggestion ID), role='listbox' on the list, role='option' and aria-selected on each item.
It points to the ID of the currently highlighted suggestion. This tells screen readers which suggestion is active, even though the focus is still on the input. Update it via JavaScript when the highlight changes.
It tells screen readers how the autocomplete works. aria-autocomplete='list' means the input offers a list of suggestions. Other values: 'inline' (inline completion), 'both' (list and inline), 'none' (no autocomplete).
Set aria-expanded='true' when suggestions are visible and 'false' when hidden. Update on show (after fetching results) and on hide (on escape, click outside, or selection). This tells screen readers whether the suggestions list is open.
Ready to master React completely?
Want to upskill yourself, crack your next interview, and get your dream job? Join our comprehensive course to dive deeper with high-quality video tutorials, solve interview questions, and a premium community.
Master React
Want to upskill yourself, crack your next interview, and get your dream job? Join our comprehensive course.

