CKTIS / HTML
list — connecting an input to suggestions
The `list` attribute connects an `input` to a `datalist` containing suggested values. It does not restrict the entered value to those suggestions.
Version: WHATWG HTML Living Standard; index snapshot date recorded separately
Syntax
<input type="text" list="choices">
<datalist id="choices">
<option value="HTML"></option>
</datalist>list references a datalist by its id in the same tree. Its value is an identifier, not a CSS selector: use topics, not #topics. The attribute applies only to appropriate input types, such as text; it does not apply to password.
The option elements in a datalist supply suggestions. list does not enforce membership: other validation constraints still apply. If selection from a closed list is required, use select.
The browser determines suggestion presentation and filtering. A missing matching element means no suggestions source. The first element with the specified id matters; if it is not a datalist, no association is established. Avoid duplicate IDs.
In the example, the DOM property input.list returns the associated datalist. The unlisted value JavaScript remains valid, so the final output line is true.
Examples
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>list example</title>
<label for="topic">Topic</label>
<input id="topic" type="text" list="topics">
<datalist id="topics">
<option value="HTML"></option>
<option value="CSS"></option>
</datalist>
<pre id="result"></pre>
<script>
const input = document.getElementById('topic');
input.value = 'JavaScript';
document.getElementById('result').textContent =
`${input.list.id}\n${input.value}\n${input.checkValidity()}`;
</script>
</html>Result
topics JavaScript true
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.