Sub topic 14
Making Search and Filters Accessible
Assume you know basic HTML forms, CSS layout, and JavaScript event handling. This chapter focuses on making search and filter controls usable with keyboards, screen readers, zoom, and touch input.
Accessibility means that people with different abilities can understand, operate, and review an interface. Search and filtering need special care because they combine form controls, changing content, keyboard interaction, and application state.
Give every control a clear name
Use a visible <label> for a search field whenever possible. The label tells all users what they can search for. Placeholder text is not a replacement because it disappears when the user types and may have insufficient contrast.
Group related filters with <fieldset> and <legend>. For example, a group of checkboxes can have the legend “Brands.” Each checkbox still needs its own label.
Use native HTML controls before building custom components. Native inputs, buttons, checkboxes, and select elements already provide much of the expected keyboard and screen-reader behavior.
<form role="search" action="/products" method="get">
<label for="product-search">Search products</label>
<input
id="product-search"
name="q"
type="search"
autocomplete="off"
>
<button type="submit">Search</button>
</form>
<fieldset>
<legend>Category</legend>
<label>
<input type="checkbox" name="category" value="boots">
Boots
</label>
<label>
<input type="checkbox" name="category" value="sandals">
Sandals
</label>
</fieldset>The role="search" landmark helps screen-reader users find the search area. Do not add redundant ARIA roles when native HTML already provides the correct meaning.
Announce changing results
When results update without a page navigation, users may not know that anything changed. Provide a status message such as “24 results found.” A role="status" region is normally announced politely, without interrupting the current speech.
Also make the result heading meaningful. For example, use “Search results for boots” rather than a generic “Results.” If a request fails, announce the error and provide a recovery action.
Avoid announcing every keystroke. Announce completed searches, applied filters, and important errors instead.
<section aria-labelledby="results-heading">
<h2 id="results-heading">Search results for boots</h2>
<p role="status" aria-live="polite">24 results found</p>
<ul>
<li><a href="/products/trail-boot">Trail boot</a></li>
<li><a href="/products/city-boot">City boot</a></li>
</ul>
</section>Support keyboard and focus behavior
A keyboard user must be able to reach every control, identify the current focus, operate it, and reach updated content. Do not remove the browser’s focus outline unless you replace it with a more visible indicator.
After applying a filter, keep focus on the filter that was changed unless the interface has a strong reason to move it. If a user activates a “View results” button on a separate filter panel, move focus to the results heading or result summary. This gives a screen-reader user an equivalent sense of location.
Autocomplete requires a predictable keyboard model. Users should be able to move from the input into suggestions with the arrow keys, accept a suggestion with Enter, and close the list with Escape. The input should expose the active suggestion through aria-activedescendant. A custom autocomplete is a composite widget, so test it carefully with real screen readers.
Make state and errors understandable
Show applied filters as removable controls with accessible names such as “Remove brand Acme.” Provide a clearly labeled “Clear all filters” action. Do not rely on color alone to show which filters are active.
Ensure text and controls meet sufficient color contrast, remain usable at high zoom, and have touch targets large enough to activate reliably. Test long labels, translated text, and error messages that wrap onto multiple lines.
Exercise
After a filter changes the results list, where should focus go?
Show answer
Keep focus on the changed filter in most interfaces. If the interaction closes a separate filter panel, move focus to the results heading or result summary and announce the new result count.