How to Create an Input With Dropdown Using HTML Only?

Learn how to create a dropdown list with an input using HTML only

To create an input field that has a related dropdown list, you need to:

  1. Create a <datalist> element with an id, and a set of <option> elements that represent options to choose from;
  2. Create an <input /> element with the list attribute that matches the id of the <datalist> element.

For example:

<input type="text" list="countryName" placeholder="Country Name" />
<datalist id="countryName">
  <option value="Germany">
  <option value="United Kingdom">
  <option value="United States of America">
  <!-- ... -->
</datalist>

Hope you found this post useful. It was published . Please show your love and support by sharing this post.