HTML Datalist
Sometimes you want suggestions without locking the user into a fixed dropdown. datalist offers autocomplete-style options for an input.
Direct answer
1) Give <datalist id="browsers"> some <option value="…"> children.
2) On the input, set list="browsers".
The user can pick a suggestion or type something else.
Input with datalist suggestions
html<label for="browser">Browser</label>
<input id="browser" name="browser" list="browsers" placeholder="Type or choose">
<datalist id="browsers">
<option value="Firefox">
<option value="Chrome">
<option value="Edge">
<option value="Safari">
</datalist>
Try it
- Create an input with a
listattribute - Add a matching
datalistid with four options - Type and pick suggestions in the browser
- Compare with a
selectthat only allows listed values
Easy mistakes
- Mismatched
list/datalistid - Expecting datalist to force only listed values (that is closer to
select) - Forgetting a label on the input
Summary
datalistsuggests values for an input- Connect with
list+ matchingid - Users may still type custom text
- Use
selectwhen the choice must be fixed
🧠 Test Your Knowledge
Test Your Knowledge
Challenge yourself with this interactive quiz and see how well you understand the topic
📝 Instructions
- Read each question carefully
- Select the best answer for each question
- You can retake the quiz as many times as you want
- Your progress will be shown at the top