HTML <datalist> Tag

The <datalist> tag is used to create a list of input options, predefined by the <input> tag. Initially, the options are hidden, the list of options becomes available when the user starts typing. The list attribute of the <input> tag must match the id of the <datalist> element.

Predefined options for input are enclosed in a nested <option> element.

Syntax

The tag content is placed between the opening (<datalist>) and the closing (</datalist>) tags.

Note: The <datalist> element isn’t supported in Safari.

Example

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
  </head>
  <body>
    <div>Choose browser</div>
    <input list="browsers" />
    <datalist id="browsers">
      <option value="Internet Explorer">
      <option value="Opera">
      <option value="Safari">
      <option value="Firefox">
      <option value="Google Chrome">
      <option value="Maxthon">
    </datalist>
  </body>
</html>

Attributes

The <datalist> tag supports Global Attributes.