The HTML <datalist> tag
The HTML <datalist> element provides a list of suggested <option> values for an <input>, connected via the input's list attribute. Unlike a <select>, the user can still type a value not in the list.
Overview
The <datalist> element offers autocomplete suggestions for a text input while still letting the user type anything they like. As they type, the browser surfaces matching suggestions, but free input remains allowed.
Wiring it up takes three steps: give the <datalist> an id, fill it with <option> values, and point the input's list attribute at that id. The options become suggestions for that field.
It is the right choice when you want to suggest values without restricting to them — recent searches, common cities, frequently used tags. When the value must be one of a fixed set, a <select> is the correct control instead.
Syntax
<input list="browsers">
<datalist id="browsers">
<option value="Chrome">
<option value="Firefox">
</datalist>
Example
<label>Fruit: <input list="fr" placeholder="Type or pick…" style="padding:6px;"></label>
<datalist id="fr">
<option value="Apple"><option value="Banana"><option value="Cherry">
</datalist>
Best practices
Frequently asked questions
What is the datalist element for?
How do I add autocomplete suggestions to an input?
What is the difference between datalist and select?
<datalist> only suggests them and still allows free input.