What is autocomplete?
An autocomplete field is a text input that shows matching suggestions as you type, so you can pick one instead of typing it all. In code (on the web and in accessibility specs) it’s called a combobox: a combination of an editable box and a list of options.
There are two important questions for every autocomplete, and testers should know the answer before starting:
- Must the user pick from the list, or is free text allowed? A city for delivery, an airport, a country or a product variant must be one of the options (it has an id behind it). A search query, a tag or a town that might not be in the list can be anything.
- Where do suggestions come from? A local list (200 countries, built into the app) is instant. A server search (millions of addresses) is slow, can fail, and answers in an unpredictable order.
Anatomy
City1
🔊 “4 results available”7
- 1
Label
Says what to type ("City"). Visible and connected to the input, like any text field.
- 2
Input (the combobox)
What the user typed. Its text is not the value yet: the value is set when an option is chosen.
- 3
Clear button
Empties the field and the selection. Needs a name ("Clear city") and a 44 pt / 48 dp touch area.
- 4
Suggestion list (listbox)
Opens below the field after enough characters. Must close on Esc, on selection and when focus leaves.
- 5
Active option
Moved with the arrow keys, chosen with Enter. Clearly visible, and different from "selected".
- 6
Matched part
The part of each option that matches the query, in bold. Must match the same way as the search (case, accents).
- 7
Result count (status)
Invisible on screen but announced: "4 results available". Also says "No results".
List, inline, or both
| Style | What happens | Typical use |
|---|---|---|
| List | A list of matching options opens under the field | Cities, addresses, products, people |
| Inline | The rest of the word is filled in and selected; typing on replaces it | Browser address bar, email domains |
| List + inline | The list opens and the first match is also completed in the field | Some address bars and code editors |
Dev note
aria-autocomplete="list", "inline" and "both". You’ll see these values in DevToolsDevToolsDeveloper tools built into browsers for inspecting pages, network traffic and errors.Open in glossary → when you inspect the field.How it differs from similar components
| Component | You type… | You get… |
|---|---|---|
| Autocomplete / combo box | Part of a name | Suggestions; one becomes the value (or free text) |
| Dropdown / select | Nothing (or one letter to jump) | One option from a fixed list |
| Search bar | A query | A results page; suggestions are only shortcuts |
| Chips / token field | Part of a name, many times | Several selected values shown as chips |
| Browser autofill | Nothing | Saved personal data filled into a form (see Text field) |
Designs & variants
Every field here works. Type a few letters (try nis, sabac or novi), use the arrow keys, Enter and Esc, then click outside.
Form value: null
List autocomplete, must pick
WebA combobox: type to filter, choose with arrows + Enter or a click. Leave the field with text that isn't a city and you get an error, not a silently invalid address.
Form value: null
Exposed dropdown menu
Android · Material 3Material's text field with a filtered menu (AutoCompleteTextView / ExposedDropdownMenuBox). Same rules: arrows, Enter, Esc, and the menu closes when focus leaves.
- Nova Pazova22330, Serbia
- Nova Varoš31320, Serbia
- Novi Bečej21220, Serbia
- Novi Kneževac23330, Serbia
Full-screen search
iOSOn phones, apps often move the field to the top and show results as a full list above the keyboard. A small floating list would be hidden behind the keyboard.
Type anna@g. Press → or Tab to accept, keep typing to overrule, Backspace to drop the suggestion.
Inline completion
WebThe rest of the text is filled in and selected: the browser address bar and email-domain helpers work like this. Typing on replaces the suggestion; deleting must not bring it back.
Form value: null
Suggestions + free text
WebWhen the list can't know every answer (small villages, new streets), the first row keeps exactly what the user typed. Then the form must accept a value without an id.
How a good autocomplete behaves
It waits for enough input. One letter matches half the list and wastes a server call. Most fields start after 2–3 characters (local lists can start at 1) and say so: “Type at least 2 letters”.
It waits for a pause, and ignores old answers. Requests are sent after a short debounceDebounceWaiting until the user stops typing for a moment before reacting, for example before searching.Open in glossary → (around 200–300 ms). Responses can arrive in any order, so the app must only show the answer to the latest query. Otherwise the slow answer for “no” overwrites the fast answer for “novi”: a race conditionRace conditionA bug that depends on the timing or order of events, so it only happens sometimes.Open in glossary →. The Search, filters & sorting page shows this with a live demo.
It matches the way people type. Case and accents are ignored (diacriticsDiacriticsAccent marks on letters, like é, ü, č or ž. Search usually should ignore them.Open in glossary →: “sabac” finds Šabac), and words in the middle count (“sad” finds Novi Sad). The Dropdown page has a matching lab for this.
It highlights the matched part, using the same matching rules. If the search ignores accents but the highlighting doesn’t, users see options with nothing bold and wonder why they’re there.
It shows the empty and the loading state. “No cities match ‘nobi’. Check the spelling.” is an empty stateEmpty stateThe screen a user sees when there is no content yet, like an empty cart or no search results.Open in glossary →; a spinner or “Searching…” covers slow networks. Silence (no list at all) looks like a broken field.
It keeps typed text and selected value apart. The text in the field is just text until the user chooses an option. If they edit the text afterwards, the selection must be cleared. And if they leave the field without choosing, a must-pick field shows an error (or accepts an exact match), but never saves “novi” as a city.
It obeys the keyboard. Arrows move through the options, Enter chooses, Esc closes the list (a second Esc may clear the field), Tab moves on. More in Accessibility.
It closes when it should: after choosing, on Esc, when focus leaves the field, and when the user taps outside.
Check this part
You type "novi" quickly and the list shows "Nova Varoš". What is the most likely cause?
Search finds Šabac for "sabac", but no letters are bold. What kind of bug is this?
A user picks "Novi Sad", then edits the text. What should happen to the selection?