Using the Datalist Element for Predefined Input Suggestions
The <datalist> element in HTML is used to create a predefined list of options for an <input> element. It allows the user to select an option from the list while also giving them the ability to enter their own value if they choose. The list of predefined values remains hidden until the user starts typing in the associated text field. The <datalist> is paired with an id attribute, and the <input> is linked to it using the list attribute.
index.html
The <datalist> element is useful when you want to provide helpful suggestions without limiting users to a fixed set of choices.
Example
When the user types in the field, the browser shows the predefined categories. If none match, the user can still enter their own value.
index.html
<label for="category">: describes the purpose of the input field;<input type="text" name="category" id="category" list="categories"/>: a text field that displays suggestions from a linked datalist;<datalist id="categories">: contains predefined options that appear as hints while typing;<option value="...">: represents each suggested item.
1. Which HTML element is used to create a drop-down list with multiple options?
2. What is the purpose of the datalist element?
3. What attribute is used to link a datalist element to an input element?
Thanks for your feedback!
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Can you show me a complete example using the `<datalist>` element?
What are some common use cases for `<datalist>` in web forms?
Are there any browser compatibility issues with `<datalist>`?
Awesome!
Completion rate improved to 2.38
Using the Datalist Element for Predefined Input Suggestions
Swipe to show menu
The <datalist> element in HTML is used to create a predefined list of options for an <input> element. It allows the user to select an option from the list while also giving them the ability to enter their own value if they choose. The list of predefined values remains hidden until the user starts typing in the associated text field. The <datalist> is paired with an id attribute, and the <input> is linked to it using the list attribute.
index.html
The <datalist> element is useful when you want to provide helpful suggestions without limiting users to a fixed set of choices.
Example
When the user types in the field, the browser shows the predefined categories. If none match, the user can still enter their own value.
index.html
<label for="category">: describes the purpose of the input field;<input type="text" name="category" id="category" list="categories"/>: a text field that displays suggestions from a linked datalist;<datalist id="categories">: contains predefined options that appear as hints while typing;<option value="...">: represents each suggested item.
1. Which HTML element is used to create a drop-down list with multiple options?
2. What is the purpose of the datalist element?
3. What attribute is used to link a datalist element to an input element?
Thanks for your feedback!