HTML list Attribute

Beginner
6 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The list attribute on an <input> links that control to a <datalist> in the same document. Its value is the datalist’s id. The browser then shows those <option> values as suggestions.

Suggestions are not a closed set — users can still type other values. For a fixed choice only, use <select> instead.

Not deprecated.

Valid HTML. Support for list on text-like inputs is wide; datalist UI and some input types still vary by browser.

Accessibility note.

Datalist popups can be awkward for zoom, high contrast, and some screen readers. Do not rely on suggestions as the only way to complete a required field.

HTML Syntax

syntax.html
<input list=" datalist-id"> … <datalist id="datalist-id">

The list value and the datalist id must match exactly (same document).

Attribute Values

A single ID reference — the id of a <datalist>:

ValueDescriptionTry it
datalist-idMust equal a <datalist id="…"> in the same pageTry it
Supported typese.g. text, search, email, url, tel, number, date/time types, range, colorTry it
Not supportedhidden, password, checkbox, radio, file, button typesTry it
Dynamic switchChange the list attribute to point at another datalist idTry it

Live Preview

Focus the field and type. Switch the linked datalist with the chips.

list target

Suggestions come from <datalist>. You can still type a custom value.

Input + datalist

list="fruits"

HTML Examples

Short, copy-ready snippets. Use Try It Yourself for a live editor.

Example 1 — Text Input Suggestions

Link a text field to a datalist of fruit names.

HTML
<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="Strawberry">
</datalist>
Try It Yourself

How It Works

  1. Give the datalist an id. Here id="fruits".
  2. Point list at that id. list="fruits" on the input creates the link.
  3. Options supply values. Each value is a suggested string.
  4. Still free text. The user may enter “Kiwi” even if it is not listed.

Example 2 — Range Tick Marks

On type="range", datalist values often appear as selectable ticks.

HTML
<label for="tip">Tip amount:</label>
<input type="range" id="tip" name="tip" min="0" max="50" list="ticks">

<datalist id="ticks">
  <option value="0" label="0%">
  <option value="10" label="Minimum">
  <option value="20" label="Standard">
  <option value="30" label="Generous">
  <option value="50" label="Max">
</datalist>
Try It Yourself

How It Works

  1. Same list pattern. list still references the datalist id.
  2. Numeric option values. They should fit the range’s min / max.
  3. Optional labels. label on options can name ticks (support varies).
  4. UI differs. Some browsers show ticks; others are quieter — always test.

Example 3 — Switch Datalist with JavaScript

Change list at runtime to point the same input at another datalist.

HTML
<label for="category">Category:</label>
<select id="category">
  <option value="fruits">Fruit</option>
  <option value="vegetables">Vegetable</option>
</select>

<label for="item">Item:</label>
<input type="text" id="item" list="fruits">

<datalist id="fruits">
  <option value="Apple">
  <option value="Pear">
</datalist>
<datalist id="vegetables">
  <option value="Carrot">
  <option value="Peas">
</datalist>

<script>
  document.getElementById("category").addEventListener("change", function () {
    var input = document.getElementById("item");
    input.setAttribute("list", this.value);
    input.value = "";
  });
</script>
Try It Yourself

How It Works

  1. Two datalists, one input. Each list has its own id.
  2. Update the link. Set the list attribute to the other datalist’s id (the IDL list property is read-only).
  3. Clear stale text. Reset value so an old fruit does not linger under vegetables.
  4. Same document only. The datalist must live in the same page as the input.

Edge Cases & Pitfalls

Most issues are wrong IDs, unsupported types, or treating datalist like select.

id

IDs must match exactly

A typo in list or id silently disables suggestions. Keep both in the same document.

scope

Not for password / checkbox / file

Per the HTML / MDN rules, list is ignored on hidden, password, checkbox, radio, file, and button inputs.

compare

Not a select replacement

Datalist suggests; select constrains. Use select when only listed values are allowed.

filter

Incompatible options are skipped

Options that do not fit the input type are left out of the suggestion set.

a11y

Popup UX varies

Zoom, high contrast, and screen readers may not treat the suggestion list like a normal listbox. Provide a clear <label> and validate on the server.

Browser Support

list is an HTML attribute on <input> in the browser. It is not a Node.js, Deno, or Bun API.

✓ Widely available on text · UI varies

list

list on text-like inputs is widely supported (Chrome 20+, Firefox 4+, Safari 12.1+, Edge 12+). Datalist presentation and range/color behavior still differ across browsers.

97% text + list (approx.)
Google Chrome 20+
Full support
Mozilla Firefox 4+
Full support
Apple Safari 12.1+
Full support
Microsoft Edge 12+
Full support
Opera 15+
Full support
Samsung Internet 4+
Full support
Internet Explorer 10+
Supported
list on text inputs Widely supported

Bottom line: Safe for progressive suggestions. Always allow free text (or use select) and test the datalist UI on target browsers.

Key Takeaways

  • Role: connect <input> to a <datalist> by matching id.
  • Suggestions only: users may enter values outside the list.
  • Types: works on many inputs; not on password, checkbox, radio, file, or buttons.
  • vs select: use select when the value must be one of the options.

One line: list="id" wires an input to a datalist of optional suggestions — not a locked menu.

Frequently Asked Questions

On an input, list points to the id of a datalist in the same document. The browser offers those option values as suggestions while the user types or opens the control.
The input element. The matching datalist must have the same id as the list value. It is not used on select.
No. Values are suggestions, not a hard limit. Users can enter other values that still pass validation. Use select when the choice must be only from a fixed list.
Most types except hidden, password, checkbox, radio, file, and button types. Common uses are text, search, email, url, tel, number, date/time types, range, and color.
Give the datalist an id, then set list to that same id on the input — for example list="browsers" with <datalist id="browsers">.
Support for list on text inputs is wide, but datalist UI and some input types still vary by browser. Always test, and do not rely on it as the only way to choose a value.

Next: longdesc

See the deprecated longdesc attribute for long image descriptions.

longdesc tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful