Sobes.tech
Junior

What is the <datalist> element in HTML5?

sobes.tech AI

Answer from AI

The <datalist> element in HTML5 is used to create a list of predefined options that the user can select when typing in the associated <input> field. This enhances user experience by providing suggestions and autocomplete.

Example usage:

<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">
  <option value="Opera">
</datalist>

In this example, a dropdown list with browser options will appear when typing in the input field.