Search autocomplete
Suggesting search queries in a dropdown as users type in the search bar of GOV.UK
When to use this component
Use search autocomplete when you are dealing with dynamic data and want to reduce typing effort for users and help them formulate search queries by filling in the blanks (think of Google search).
When not to use this component
- Do not use search autocomplete when you are dealing with a limited database and users can easily find what they need with a simple search.
- Do not use search autocomplete unless the model is properly trained and you have validated it provides relevant and factually correct suggestions.
How it works
The data model behind the autocomplete feature is powered by Google Vertex AI Search, the search product that the Search team launched on GOV.UK in February 2024. This model is trained on anonymised user search queries (from people who have consented to analytics tracking), which Google processes and refines to provide relevant autocomplete suggestions.
The autocomplete suggestions appear underneath the search box after 3 characters have been typed – as suggestions are more relevant after this threshold. The suggested keywords to formulate the new query are highlighted in bold (as it is a standard pattern), and we limit the suggestions to 5 in order to reduce cognitive load and prevent unnecessary scrolling. Selecting a suggestion from the dropdown will update the search query in the search bar and take the user to the search results page – showing results relevant to the selected query.
Useful reads
Differences with how search autocomplete is used on the Design System website
The Design System website (opens in a new tab) uses search autocomplete in a slightly different way – known internally as the accessible autocomplete (opens in a new tab).
Typing and suggestions behaviour
On the GOV.UK search autocomplete, a maximum of 5 search query suggestions appear in a dropdown after typing 3 characters. The suggestions show keywords to add to what the user has typed in the search bar. The dropdown pushes the content down to avoid any overlays – which are a problem for screen readers.
On the other hand, on the Design system page autocomplete you get an unlimited amount of results in a dropdown as soon as you type, and the dropdown overlays the content and includes interal scrolling. The search results (which are NOT search query suggestions) match the keywords typed and are populated from a static data list. For example if I type ‘ra‘, I get the result ‘radio buttons‘.
Styling
-
The hover state of the GOV.UK search autocomplete uses a light grey background and underline the text – while the hover state used in the design systems uses a blue background and white text. The reason why the Search team made this change is because on GOV.UK sometimes the search autocomplete dropdown sits on top of a blue background (for example on the homepage), which merges with the blue colour on hover and makes the autocomplete suggestions hard to read. For this reason we changed it to a light grey background with text underline, which passed the DAC usability audit.
-
The horizontal grey lines that separate the suggestions in the dropdown have a 15px padding left and right on GOV.UK – while the lines go edge to edge in the Design System search. The extra space added in the GOV.UK variation allows the list of suggestions breathe more, which contributes to having better visual harmony and a feeling of clean design.
Our suggestion would be to update the Design System hover state and line separators to the how they work on GOV.UK – so they are more consistent.
Accessibility
The Design system team recently iterated the way they present search suggestions (Dec 2024) to make it more accessible for users who use accessibility functionalities that enlarge the content on the screen to make it easier to see and read. Read more about this (opens in a new tab).
The search autocomplete used on GOV.UK should follow the same approach to improve accessibility and bring consistency.
Date | Description | Document | Format |
---|---|---|---|
July 2024 | Design System DAC audit reporting issues with search autocomplete dropdown – Design System team |
Autocomplete - Lack of visual cue for results (opens in a new tab) | Github |
June 2024 | Search team desk research analysis on how search is used on GOV.UK (before autocomplete was implemented) – Search team |
Site search desk research and analytics findings (opens in a new tab) | Google Slides |
June 2024 | Pop up research analysis on autocomplete (and filters) – Search team |
GOV.UK Search Autocomplete + filters pop up research findings (opens in a new tab) | Google Slides |
Accessibility criteria
How to report an issue
If you happen to come across an issue:
- Report it on Github (opens in a new tab).
- Once the issue has been added, update this document by adding the title and Github Issue’s link.
- Give yourself a high-five.
Help improve this page
To help make sure that this page is useful, relevant and up to date, submit a GitHub issue (opens in a new tab) with your proposed updates.