HTML list attribute

list attribute associates input element to the source of suggested list of predefined options.


<p>Which is your favourite subject.</p>
<input list="data">
<datalist id="data">
 <option value="physics">Physics
 <option value="chemistry">Chemistry
 <option value="mathematics">Mathematics
 <option value="none">None
Try </>

Here datalist contains the predefined options to aid the user in choosing the option.

list attribute value

The value of this attribute is simple text.

when the user selects one option then the value of that option becomes the value of input element.

If a browser does not support datalist element then the fallback content can be placed inside select element. The options can be placed inside the select element.


<input type="text" list="gender">
<datalist id="gender">
 ot select gender from the list:
<select name="sex">
 <option value=" ">

Related Tags

Only <input> tag supports the list attribute.

Was this article helpful?




Get the newsletter