datalist
Definition and Usage
The <datalist> tag specifies a list of pre-defined options for an <input> element.The <datalist> tag is used to provide an "autocomplete" feature on <input> elements. Users will see a drop-down list of pre-defined options as they input data. The HTML<datalist>
element contains a set of <option> elements that represent the values available for other controls. For example, if a user began entering some text into a text
field, a list would drop down with prefilled values that they could choose from.
Usage
The<datalist>
tag can be used in conjunction with an <input> element that contains a list
attribute.
The list
attribute is linked to the <datalist>
tag by the <datalist>
tag's ID. For example, if the <datalist>
tag contains id="myData"
, then the list
attribute will look like this: list="myData"
.
You can fill the <datalist>
element by nesting <option> tags inside the <datalist>
tag.