The <datalist> element
The <datalist> tag gives an <input> a list of suggested values, which appear as autocomplete options while the user types. Link the two by setting the input’s list attribute to the datalist’s id. Unlike <select>, the user can still type any value that isn’t on the list.
Last updated: October 3, 2026
Quick facts
| Category | Flow content, phrasing content |
| Content model | Either phrasing content or zero or more <option> elements |
| Tag omission | Neither the start nor the end tag can be omitted |
| Permitted parents | Any element that accepts phrasing content |
| DOM interface | HTMLDataListElement |
Syntax
Live example
Edit the code below and watch the preview update instantly.
Attributes
| Attribute | Description |
|---|---|
| — | <datalist> itself takes only global attributes; give it an id and point an input’s list attribute at it. Each <option> uses value (and optionally label). |
Common examples
Suggestions for a text field
Visitors can pick a suggestion or type something else.
Tick marks on a slider
A datalist on type="range" adds tick marks at suggested values.
Suggestions loaded from data
Fill the list with JavaScript, for example from a list of cities.
<datalist> vs a JavaScript autocomplete
<datalist> gives you suggestions with no JavaScript at all, works with the keyboard and screen readers, and uses the familiar dropdown of each browser. Its limits: you can’t style the dropdown, matching rules vary between browsers, and it’s awkward with thousands of options.
A JavaScript autocomplete library gives full control over the look, search logic and remote loading as people type — but you must make it accessible yourself. For simple suggestion lists, datalist is the quickest win.
| <datalist> | JS autocomplete | |
|---|---|---|
| JavaScript needed | No | Yes |
| Styling the dropdown | No | Full |
| Large or remote lists | Awkward | Yes |
Common mistakes to avoid
- A mismatched id. The input’s
listmust match the datalist’sidexactly. - Expecting it to restrict the answer. Visitors can still type anything; use <select> if only listed values are allowed.
- Putting text between option tags only. Browsers fill the field from the
valueattribute; always set it. - Hundreds of options. Long lists are slow to browse; keep suggestions short or filter them as people type.
Accessibility & SEO tips
- Always give the input a visible <label> — the suggestion list doesn’t replace it.
- Validate the value on the server too, since visitors can type anything.
- Test the suggestions on a phone; mobile browsers show them in different places, such as above the keyboard.
- Pick suggestions based on what most people actually type — they save typing on phones and reduce spelling mistakes in your form data.
Browser support
Supported in all modern browsers, including Chrome, Edge, Firefox, Safari and their mobile versions. It was introduced with HTML5, and only very old browsers such as Internet Explorer 8 needed workarounds. The look of the suggestion list and how it matches text differ between browsers.
Tutorial: HTML forms tutorial