Skip to main content
Official government website

Filter

A collapsed panel of option groups that narrows a list of results.

Examples
HTML and React
Group
Navigation
On this page

Preview

Filter
Open in new tab

The filter sits above a list of results, closed until the user asks for it. Inside are filter groups, each a named set of checkboxes that also starts closed, and an Apply button. Both levels are built on the native <details> element, so they open, close and take keyboard focus with no JavaScript.

The panel is a form that submits with GET, so the chosen options end up in the page address. The page reads them and renders the narrowed results, and users can bookmark or share a filtered list.

Usage

When to use

  • Use a filter on a list long enough that users need to narrow it, such as a list of services.
  • Use it when the results can be sorted into a few clear groups of options.

When not to use

  • Do not use it when users know what they are looking for by name; use search.
  • Do not use it to collect answers in a form; use checkboxes in a fieldset.

Best practices

Name groups after what users are looking for

Write each group’s name as a short noun phrase in sentence case, such as “Service type”, using the words users would use rather than internal categories.

Keep the options few

Keep each group to a handful of options, and the filter to a few groups. If a group needs many options, the list probably needs search instead.

Show the chosen options after applying

When the page reloads with a filter applied, check the options the user chose and open the groups they are in, so users can see why the list is shorter.

Keep the rest of the page’s state

Applying replaces the page address’s query with the filter’s own fields, so a search term or sort order already in the address is lost. Carry it over with hidden inputs inside the panel, before the button, such as <input type="hidden" name="q" value="passport">. In React, pass them as children of Filter.

Filter groups

A filter group labels its options with its summary. Give the summary an id and point the options’ aria-labelledby at it, so screen readers announce the group’s name with each checkbox. The React FilterGroup wires this up for you, and puts an id you pass on the summary.