👀 Live Preview
Click the field and type A or B to see suggestions:
The input uses list="demo-fruits" linked to the datalist below it in the DOM.

The list attribute is an HTML feature that connects an <input> element to a <datalist> element. It provides a predefined set of autocomplete suggestions while still letting users type their own value. This is not related to <ul> or <ol> bullet lists—those are separate elements with no list attribute.
Linked by id.
list="fruits".
Suggest, not restrict.
Free text vs fixed.
Common confusion.
Swap datalists.
listThe primary purpose of the list attribute is to associate an <input> with a set of predefined options defined in a <datalist>. Users see matching suggestions as they type, which speeds up data entry and reduces typos on common values like countries, colors, or product names.
Unlike a <select> dropdown, the user is not limited to the suggested values—they can submit any text that fits the input’s validation rules.
The old meta description sometimes called this a “list styling” attribute for ordered and unordered lists. That is incorrect. Use <ul>, <ol>, and CSS for document lists; use list only on <input> with <datalist>.
Point the input’s list attribute at the id of a <datalist>:
<label for="fruit">Select a fruit:</label>
<input type="text" id="fruit" name="fruit" list="fruits">
<datalist id="fruits">
<option value="Apple">
<option value="Banana">
<option value="Orange">
<option value="Grapes">
<option value="Strawberry">
</datalist><input> elements (text, search, url, tel, email, number, etc.).id of a <datalist> in the document—no # prefix.datalist id must be unique and must match the list value exactly.<option value="..."> inside the datalist.input.list returns the linked HTMLDataListElement.The list attribute accepts a single token: the id of a <datalist> element.
list="fruits" — Links to <datalist id="fruits">.list="countries" — Another datalist for a different input.Update the association in JavaScript:
document.getElementById("dynamicInput").setAttribute("list", "vegetables");
// or: input.list = document.getElementById("vegetables");| Use Case | Markup | Notes |
|---|---|---|
| Fruit suggestions | <input list="fruits"> | + <datalist id="fruits"> |
| Email domain hints | list="domains" | Works with type="email" |
| Strict dropdown | Use <select> | Not list |
| JavaScript link | input.list = datalistEl | Swap suggestions |
| Label option text | <option label="..."> | Display differs from value |
| Element / Context | Supported? | Notes |
|---|---|---|
<input> | Yes | Primary use case |
<datalist> | Target | Referenced by list id |
<ul>, <ol> | No | Document lists, not this attribute |
<select> | No | Use options inside select instead |
list + datalist vs <select>| Feature | input list + datalist | <select> |
|---|---|---|
| User can type freely | Yes | No (unless multiple + special cases) |
| Suggestions only | Yes | Fixed options |
| Native dropdown UI | Autocomplete popup | Full select menu |
| Best for | Known values + custom entry | Must pick one option |
Fruit autocomplete, switching between two datalists, and updating list with JavaScript.
Click the field and type A or B to see suggestions:
The input uses list="demo-fruits" linked to the datalist below it in the DOM.
<label for="fruit">Select a Fruit:</label>
<input type="text" id="fruit" name="fruit" list="fruits">
<datalist id="fruits">
<option value="Apple">
<option value="Banana">
<option value="Orange">
<option value="Grapes">
<option value="Strawberry">
</datalist>list="fruits" connects the input to <datalist id="fruits">. The id must match exactly.
Use different suggestion sets for different contexts:
<input id="food" list="fruits" placeholder="Pick a food">
<button type="button" id="useVeg">Use vegetables list</button>
<datalist id="fruits">…</datalist>
<datalist id="vegetables">…</datalist>
<script>
document.getElementById("useVeg").onclick = function () {
document.getElementById("food").setAttribute("list", "vegetables");
};
</script>Changing the list attribute re-points the input to a different datalist without recreating the input element.
function updateListAttribute(category) {
var input = document.getElementById("dynamicInput");
input.setAttribute("list", category === "veg" ? "vegetables" : "fruits");
}Dynamic updates keep one input field but swap suggestion sources based on user choices or API data.
<label> — Use for matching the input id so screen readers announce the field purpose.select when choice must be restricted — For required fixed options, a select is more predictable for accessibility.Value = datalist id.
Browser reads options.
Filtered datalist values.
Pick or type custom value.
The list attribute with <datalist> is supported in all modern browsers. Styling of the suggestion popup is limited and varies by platform.
Chrome, Firefox, Safari, and Edge support input list + datalist.
Bottom line: Safe for progressive enhancement; validate submitted values on the server.
list to a valid datalist idselect when only fixed options are allowedlist with <ul> / <ol>list on <select> (invalid)The list attribute is a valuable tool for creating interactive, user-friendly forms in HTML. By associating <input> elements with <datalist> elements, you guide users through predefined options while keeping input flexible.
Remember: this attribute is about autocomplete suggestions, not bullet or numbered lists. Pair it with proper labels, validate on the server, and choose select when users must pick exactly one option.
listBookmark these before adding autocomplete to forms.
Linked by id
SyntaxSuggest, not lock
BehaviorDifferent feature
CompareJS updates list
DynamicServer-side check
A11y<input> to a <datalist> by id so the browser shows autocomplete suggestions from the datalist options.<ul> and <ol> elements. The list attribute is only for <input> + <datalist>.id of a <datalist> element, without a hash—for example list="fruits" matches <datalist id="fruits">.select restricts choices. input list suggests options but allows custom text the user types.input.setAttribute("list", "newId") or assign input.list to a different datalist element.Practice linking list on <input> to <datalist> options in the Try It editor.
5 people found this page helpful