Codectionary / Developer documentation / HTML

<datalist>

The <datalist> element provides a list of predefined autocomplete suggestions for an <input> element, without restricting the user to only those choices — unlike <select>, users can still type a custom value. It is connected to an input via a matching list attribute and id.

Syntax

<input list="options" name="choice">
<datalist id="options">
  <option value="Option A">
  <option value="Option B">
</datalist>

Examples

Basic Autocomplete

Suggesting common browser names while allowing free text.

<label for="browser">Choose a browser:</label>
<input list="browsers" id="browser" name="browser">
<datalist id="browsers">
  <option value="Chrome">
  <option value="Firefox">
  <option value="Safari">
  <option value="Edge">
</datalist>

Number Suggestions

Using datalist to suggest common numeric values.

<label for="rating">Rating:</label>
<input type="range" list="ratings" id="rating" min="0" max="10">
<datalist id="ratings">
  <option value="0"></option>
  <option value="5"></option>
  <option value="10"></option>
</datalist>

City Search Suggestions

Suggesting cities while allowing any typed value.

<input list="cities" name="city" placeholder="Search for a city">
<datalist id="cities">
  <option value="Manchester">
  <option value="London">
  <option value="Leeds">
</datalist>

Attributes

  • id (string): Referenced by the input's list attribute

Best practices

  • Use datalist when you want to suggest common values without forcing the user to pick only from a fixed list — use select for that instead
  • Connect it to an input using matching list and id attributes
  • Keep the suggestion list reasonably short and relevant so it stays genuinely useful
  • Test the visual behavior across browsers, since datalist styling and interaction is less consistent than other form controls

At a glance

Purpose
Structure and meaning for web content
File extension
.html · .htm
Runs in
Web browsers
Usually used with
CSS and JavaScript

Specifications & further reading

Related HTML documentation