HTML: datalist
The <datalist> element provides suggestions for an input without restricting the user to those suggestions.
What you will learn
- How to connect a datalist to an input
- How suggestions differ from a select menu
- Why submitted values still need validation
Minimal example
<label for="browser">Browser</label>
<input id="browser" name="browser" list="browsers">
<datalist id="browsers">
<option value="Chrome">
<option value="Firefox">
</datalist>Users may choose a suggestion or type a different value. Use select when the value must be one of a fixed set.
Common mistakes
- Do not treat suggestions as validation or authorization.
- Keep the list short and useful; a large list may be difficult to navigate.
- Validate and normalize the submitted value on the server.