Skip to content
Tutorials Center
My learning

Topics

HTML Reference ยท Forms

The <datalist> element

Reference for the HTML <datalist> element: offering suggested values for an input with the list attribute, which input types support it, limits and technical details.

The <datalist> element holds a set of <option> elements that act as suggestions for an <input>. You connect them by giving the datalist an id and putting that id in the input's list attribute. The user can pick a suggestion or type something else entirely: a datalist never restricts the value.

HTML
<label for="fruit">Favorite fruit</label>
<input id="fruit" name="fruit" list="fruit-ideas">
<datalist id="fruit-ideas">
  <option value="Apple"></option>
  <option value="Mango"></option>
</datalist>

The datalist itself is never rendered; browsers show its options in their own suggestion popup.

Try it

Suggestions for text, range and color

On the range slider, most browsers draw tick marks at the suggested values. On the color input, some browsers show the suggested swatches in the picker.

Attributes

This element has no attributes of its own; give it an id so an input can point at it. It accepts the global attributes.

The connection lives on the input: list="datalist-id". The list attribute works on these input types: text, search, url, tel, email, number, range, date, month, week, time, datetime-local and color. It is ignored on password, checkbox, radio, file, hidden and the button types.

Usage notes

  • Suggestions, not choices. Any value is still allowed. If the user must pick from a fixed list, use <select> instead.
  • value is what gets inserted. Each option's value becomes the input's value. An option's text or label may be shown next to it as a hint, but how much is displayed varies between browsers.
  • Matching is up to the browser. Browsers filter the list as the user types; some match only the start of each value, others match anywhere.
  • autocomplete can crowd it out. The browser's own saved entries may appear alongside your suggestions. Setting autocomplete="off" on the input keeps the list focused on your options.
  • Disabled options are not offered as suggestions.
  • Not styleable. The popup is drawn by the browser; you can't style it with CSS. If you need a fully custom combobox, you'll need JavaScript and ARIA.
  • Accessibility. An input with a list is exposed as a combobox, so screen readers announce that suggestions are available. Mobile support and the look of the popup differ widely, so test with real devices.

Technical summary

Content categories Flow content, phrasing content
Permitted content Either phrasing content, or zero or more <option> and script-supporting elements
Tag omission None; both the start and end tags are required
Permitted parents Any element that accepts phrasing content
Implicit ARIA role listbox
DOM interface HTMLDataListElement
Default display none

Browser support

Supported in every current browser. The way suggestions are shown, and support on some types such as color and the date and time inputs, varies between browsers and platforms.