Form Input Datalist Autocomplete

Provide native autocomplete suggestions using the datalist element paired with a text input for enhanced UX.

HtmlForm Validation

Code

htmlsnippet
12 lines
<form>
  <label for="browser">Choose a browser:</label>
  <input type="text" id="browser" name="browser"
    list="browsers" autocomplete="off" />
  <datalist id="browsers">
    <option value="Chrome">
    <option value="Firefox">
    <option value="Safari">
    <option value="Edge">
  </datalist>
  <button type="submit">Submit</button>
</form>

How the snippet works

<datalist> attaches suggestion options to a text input natively.

The form collects input via type="text", type="submit" fields, each tied to a <label> so every control announces what it is.

Script and styles anchor onto ids browser, browsers, so behavior and styling stay decoupled from the tag names.

Key statements

<label for="browser">Choose a browser:</label>
<input type="text" id="browser" name="browser"
list="browsers" autocomplete="off" />
<datalist id="browsers">

Interactive Tools for This Topic

FAQ

Which non-generic elements does the markup use?
`<form>`, `<label>`, `<input>`, `<datalist>`, `<option>`, `<button>` — each carries native semantics (or a browser behavior) that generic containers do not.