HTML Datalist: Suggestions Without Fixed Choices
Connect input and datalist
The datalist element defines suggestions for another control. The input list attribute matches the datalist ID. The options provide candidate values, not a mandatory set.
<label> City <input name="city" list="cities"></label><datalist id="cities"> <option value="Baku"></option> <option value="Stockholm"></option></datalist>The browser can suggest both cities while the user types.
Values outside the suggestions
A text input linked to a datalist can still accept other text. Adding options does not make a value mandatory or enforce membership. Use select for a fixed menu, and validate against a trusted list on the server when necessary.
<label> Topic <input list="topics" value="Rust"></label><datalist id="topics"> <option value="HTML"></option> <option value="CSS"></option></datalist>Rust is still a valid text value.
Suggestions on a numeric scale
Some numeric controls can use datalist values as suggested positions. A range input still obeys its min, max and step; browsers differ in whether and how they draw tick marks.
<label> Brightness <input type="range" min="0" max="100" step="10" value="50" list="levels"></label><datalist id="levels"> <option value="0"></option> <option value="50"></option> <option value="100"></option></datalist>The slider starts at 50; other allowed values are not prohibited.
Common mistakes and practice
Keep the input label even when suggestions are present. Popup styling, zoom behavior and screen-reader announcements vary. If suggestions are essential, test a usable alternative; do not assume every browser displays them.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
HTML Datalist: Suggestions Without Fixed Choices — Knowledge Check
Apply the control concepts taught in this lesson.
What connects an input to a datalist?
Can a text input accept an unlisted value?
Which element is appropriate for a fixed menu?
What should option values in a datalist represent?
A browser does not show the suggestion UI. What should remain usable?