Course contentsShow
← Web Development
Lesson 931 of 2,98216. Forms and ValidationFree lesson

Autocomplete and Search Patterns

Building accessible autocomplete with aria-autocomplete, managing focus, and announcing result counts.

Autocomplete and Search Patterns

You'll learn how to build autocomplete interfaces that assistive technologies can properly announce and navigate.

What Autocomplete Means for Accessibility

An autocomplete or search widget displays a list of suggestions as the user types. For sighted users, this is visually obvious—but screen reader users need explicit ARIA attributes to understand what's happening, how many results were found, and which suggestion they're focused on.

Core ARIA Attributes for Autocomplete

Use aria-autocomplete on the input to describe the behavior:

  • aria-autocomplete="list" – suggestions appear in a popup list
  • aria-autocomplete="inline" – suggestion completes the input inline
  • aria-autocomplete="both" – combination of list and inline

The input also needs:

  • aria-controls pointing to the result container's id
  • aria-expanded="true" when results are visible
  • role="combobox" to establish the pattern

The results container should have role="listbox" and each result role="option".

Announcing Result Counts

Use a live region with aria-live="polite" and aria-atomic="true" to announce the count when results update:

<div aria-live="polite" aria-atomic="true" class="sr-only">
  5 results available
</div>

Managing Focus

When users arrow down into results, move aria-activedescendant on the input to reference the highlighted option's id. This tells screen readers which suggestion is active without actually moving DOM focus from the input.

Think of it like a waiter announcing each dish on a menu as you point, without making you hold each plate.

Key Takeaway:
Accessible autocomplete requires aria-autocomplete, aria-expanded, a listbox for results, live region announcements for result counts, and aria-activedescendant to manage virtual focus as users navigate suggestions.