Support0

HTML datalist playground

Explore datalist as a collection of suggested values for an input. Change the control type, configure attributes, and compare native menus, range ticks, and pickers without restricting the value to the available options.

Ask AI

HTML datalist playground

Response generated with openai/gpt-5.4-nano. AI can make mistakes. Always review the result.
input type="text"

Type in the field or open its native suggestions. Values outside the list are still allowed.

Current value No value

Configured suggestions

  • HTMLMarkup language
  • CSSStyle sheets
  • JavaScriptProgramming language
  • TypeScriptTyped JavaScript
HTML
<label for="preferred-technology">Preferred technology</label>
<input
  type="text"
  id="preferred-technology"
  name="suggested-value"
  list="technology-suggestions"
  placeholder="Type or choose a technology"
  autocomplete="off"
/>

<datalist id="technology-suggestions">
  <option value="HTML" label="Markup language"></option>
  <option value="CSS" label="Style sheets"></option>
  <option value="JavaScript" label="Programming language"></option>
  <option value="TypeScript" label="Typed JavaScript"></option>
</datalist>

Educational guide to datalist

Suggest values while keeping input open

Connect an input to a suggestion list while preserving free-form entry. Learn which value is inserted, what validates the field, and when another control is a better fit.

Mental model

There is an editable field, a source of suggestions, and a final value. Each part has a different responsibility.

  1. input · entry

    Receives focus, has a label, and holds the value that would be submitted under its name.

  2. datalist · suggestions

    Groups options and connects to the field through list and id. It is not another form field.

  3. value · final data

    Can come from an option or free-form typing, subject to the input constraints.

Field + suggestions → editable valueStatic diagram. The list is not drawn as a menu here: the following examples use whatever native popup the browser chooses to offer.

datalist helps complete a value. It does not make the field a closed choice or validate list membership on its own. First decide whether your product accepts new values; that decision determines whether suggestions are the right pattern.

Association and free-form entry

The label identifies the field; list identifies its suggestion source.

The label for matches the input id. The input list instead matches the datalist id, without #. Use unique IDs within the same document tree: repeating a recipe with the same IDs can connect the field to another list.

A suggested technology or one you type yourself

Reference suggestions for this example:

  • HTML
  • CSS
  • JavaScript
  • TypeScript
Focus the field and try opening its suggestions or typing “CSS”. You can also type “Astro”, which is not in the list. The visible reference lets you discover the options even if no popup appears.
A suggested technology or one you type yourself
<div class="datalist-scene-association">
<label for="datalist-guide-association-input">Technology (other values are welcome)</label>
<input
  type="text"
  id="datalist-guide-association-input"
  name="suggested-value"
  list="datalist-guide-association-options"
  autocomplete="off"
/>

<datalist id="datalist-guide-association-options">
  <option value="HTML" label="Markup language"></option>
  <option value="CSS" label="Style sheets"></option>
  <option value="JavaScript" label="Programming language"></option>
  <option value="TypeScript" label="Typed JavaScript"></option>
</datalist>
<p>Reference suggestions for this example:</p>
<ul>
  <li>HTML</li>
  <li>CSS</li>
  <li>JavaScript</li>
  <li>TypeScript</li>
</ul>
</div>
:root {
  color-scheme: light dark;
}

.datalist-scene-association {

  display: grid;
  gap: 1rem;
  min-inline-size: 0;

  label {
    font-size: 1rem;
  }

  :is(input, select) {
    box-sizing: border-box;
    inline-size: 100%;
    min-inline-size: 0;
    max-inline-size: 100%;
    min-block-size: 2.75rem;
    padding: 0.5rem;
    border: 1px solid light-dark(oklch(0.38 0.008 95), oklch(0.78 0.018 260));
    border-radius: 16px;
    corner-shape: squircle;
    background: light-dark(color-mix(in oklch, oklch(0.95 0.008 95) 94%, white), color-mix(in oklch, oklch(0.22 0.024 260) 92%, black));
    color: light-dark(oklch(0.22 0.01 95), oklch(0.95 0.01 95));
    font: inherit;
    line-height: 1.5;

    &:focus-visible {
      outline: 3px solid light-dark(oklch(0.46 0.14 261), oklch(0.82 0.18 261));
      outline-offset: 3px;
    }
  }

  p, ul {
    margin: 0;
    font-size: 1rem;
    line-height: 1.5;
  }

  ul {
    padding-inline-start: 1.5rem;
  }

  li {
    overflow-wrap: anywhere;
  }

  @media (forced-colors: active) {
    :is(input, select) {
      border-color: ButtonText;
      background: Canvas;
      color: CanvasText;

      &:focus-visible {
        outline-color: Highlight;
      }
    }
  }
}

Activation, filtering, and the number of visible results depend on the browser and device. Do not assume fuzzy search or an identical keyboard shortcut. The visible list in this recipe is reference text, not a second interactive menu.

value versus label

What helps identify an option can differ from what is inserted into the field.

With value="MAD" label="Madrid", choosing the suggestion inserts MAD. Label presentation varies. Also distinguish option label, which describes a suggestion, from the input label, which names the whole field.

A code and its description

Reference suggestions for this example:

  • MAD — Madrid
  • LIS — Lisbon
  • ROM — Rome
Choose a suggestion if your browser offers it and observe the code left in the input. The reference keeps code–city pairs visible without relying on the popup format.
A code and its description
<div class="datalist-scene-values">
<label for="datalist-guide-values-input">Airport code (other values are welcome)</label>
<input
  type="text"
  id="datalist-guide-values-input"
  name="suggested-value"
  list="datalist-guide-values-options"
  autocomplete="off"
/>

<datalist id="datalist-guide-values-options">
  <option value="MAD" label="Madrid"></option>
  <option value="LIS" label="Lisbon"></option>
  <option value="ROM" label="Rome"></option>
</datalist>
<p>Reference suggestions for this example:</p>
<ul>
  <li>MAD — Madrid</li>
  <li>LIS — Lisbon</li>
  <li>ROM — Rome</li>
</ul>
</div>
:root {
  color-scheme: light dark;
}

.datalist-scene-values {

  display: grid;
  gap: 1rem;
  min-inline-size: 0;

  label {
    font-size: 1rem;
  }

  :is(input, select) {
    box-sizing: border-box;
    inline-size: 100%;
    min-inline-size: 0;
    max-inline-size: 100%;
    min-block-size: 2.75rem;
    padding: 0.5rem;
    border: 1px solid light-dark(oklch(0.38 0.008 95), oklch(0.78 0.018 260));
    border-radius: 16px;
    corner-shape: squircle;
    background: light-dark(color-mix(in oklch, oklch(0.95 0.008 95) 94%, white), color-mix(in oklch, oklch(0.22 0.024 260) 92%, black));
    color: light-dark(oklch(0.22 0.01 95), oklch(0.95 0.01 95));
    font: inherit;
    line-height: 1.5;

    &:focus-visible {
      outline: 3px solid light-dark(oklch(0.46 0.14 261), oklch(0.82 0.18 261));
      outline-offset: 3px;
    }
  }

  p, ul {
    margin: 0;
    font-size: 1rem;
    line-height: 1.5;
  }

  ul {
    padding-inline-start: 1.5rem;
  }

  li {
    overflow-wrap: anywhere;
  }

  @media (forced-colors: active) {
    :is(input, select) {
      border-color: ButtonText;
      background: Canvas;
      color: CanvasText;

      &:focus-visible {
        outline-color: Highlight;
      }
    }
  }
}

For a form, the relevant data is the current input value under its name; datalist does not submit another selection. If you need to show a description and store a hidden identifier with a mandatory mapping, design that relationship explicitly: datalist does not enforce it.

Suggestions and validation are independent

required demands content; the type and other attributes define the field constraints.

An empty email required field is invalid, as is text that fails the email format. A valid address outside the suggestions can still pass native validation. Likewise, min, max, and step constrain compatible types: options do not replace these attributes.

Required email with example addresses

Type “other@example.net”: it satisfies the email type despite not being a suggestion. “no-at-sign” and an empty field fail its constraints. This scene lets you edit the value; it includes no submission or custom validation result.
Required email with example addresses
<div class="datalist-scene-validation">
<label for="datalist-guide-validation-input">Team email (required)</label>
<input
  type="email"
  id="datalist-guide-validation-input"
  name="suggested-value"
  list="datalist-guide-validation-options"
  required
/>

<datalist id="datalist-guide-validation-options">
  <option value="design@example.com"></option>
  <option value="team@example.com"></option>
</datalist>
</div>
:root {
  color-scheme: light dark;
}

.datalist-scene-validation {

  display: grid;
  gap: 1rem;
  min-inline-size: 0;

  label {
    font-size: 1rem;
  }

  :is(input, select) {
    box-sizing: border-box;
    inline-size: 100%;
    min-inline-size: 0;
    max-inline-size: 100%;
    min-block-size: 2.75rem;
    padding: 0.5rem;
    border: 1px solid light-dark(oklch(0.38 0.008 95), oklch(0.78 0.018 260));
    border-radius: 16px;
    corner-shape: squircle;
    background: light-dark(color-mix(in oklch, oklch(0.95 0.008 95) 94%, white), color-mix(in oklch, oklch(0.22 0.024 260) 92%, black));
    color: light-dark(oklch(0.22 0.01 95), oklch(0.95 0.01 95));
    font: inherit;
    line-height: 1.5;

    &:focus-visible {
      outline: 3px solid light-dark(oklch(0.46 0.14 261), oklch(0.82 0.18 261));
      outline-offset: 3px;
    }
  }

  p, ul {
    margin: 0;
    font-size: 1rem;
    line-height: 1.5;
  }

  ul {
    padding-inline-start: 1.5rem;
  }

  li {
    overflow-wrap: anywhere;
  }

  @media (forced-colors: active) {
    :is(input, select) {
      border-color: ButtonText;
      background: Canvas;
      color: CanvasText;

      &:focus-visible {
        outline-color: Highlight;
      }
    }
  }
}

Browser validation helps people use the form; the server validates received data. If you only accept catalogue members, check this on the server and choose an interaction that communicates the restriction. Do not try to enforce it through required alone.

Choosing datalist, select, or autocomplete

Choose by the data contract and user needs, rather than list length alone.

Use input + datalist to suggest without blocking new values. A select provides a choice among defined options: its visible text and submitted value can also differ. For a few options that should be visible together, consider native radios.

The same catalogue, two contracts

The first field lets you type “Astro”. The select only offers HTML, CSS, JavaScript, and TypeScript; its initial empty option does not satisfy required. Interact with the native controls using a keyboard or pointer.
The same catalogue, two contracts
<div class="datalist-scene-decision">
<label for="datalist-guide-decision-input">Suggested technology (free-form entry)</label>
<input
  type="text"
  id="datalist-guide-decision-input"
  name="suggested-value"
  list="datalist-guide-decision-options"
  autocomplete="off"
/>

<datalist id="datalist-guide-decision-options">
  <option value="HTML" label="Markup language"></option>
  <option value="CSS" label="Style sheets"></option>
  <option value="JavaScript" label="Programming language"></option>
  <option value="TypeScript" label="Typed JavaScript"></option>
</datalist>
<label for="datalist-guide-closed-select">Catalogue technology (required)</label>
<select id="datalist-guide-closed-select" name="closed-technology" required>
  <option value="">Choose a technology</option>
  <option value="HTML">HTML</option>
  <option value="CSS">CSS</option>
  <option value="JavaScript">JavaScript</option>
  <option value="TypeScript">TypeScript</option>
</select>
</div>
:root {
  color-scheme: light dark;
}

.datalist-scene-decision {

  display: grid;
  gap: 1rem;
  min-inline-size: 0;

  label {
    font-size: 1rem;
  }

  :is(input, select) {
    box-sizing: border-box;
    inline-size: 100%;
    min-inline-size: 0;
    max-inline-size: 100%;
    min-block-size: 2.75rem;
    padding: 0.5rem;
    border: 1px solid light-dark(oklch(0.38 0.008 95), oklch(0.78 0.018 260));
    border-radius: 16px;
    corner-shape: squircle;
    background: light-dark(color-mix(in oklch, oklch(0.95 0.008 95) 94%, white), color-mix(in oklch, oklch(0.22 0.024 260) 92%, black));
    color: light-dark(oklch(0.22 0.01 95), oklch(0.95 0.01 95));
    font: inherit;
    line-height: 1.5;

    &:focus-visible {
      outline: 3px solid light-dark(oklch(0.46 0.14 261), oklch(0.82 0.18 261));
      outline-offset: 3px;
    }
  }

  p, ul {
    margin: 0;
    font-size: 1rem;
    line-height: 1.5;
  }

  ul {
    padding-inline-start: 1.5rem;
  }

  li {
    overflow-wrap: anywhere;
  }

  @media (forced-colors: active) {
    :is(input, select) {
      border-color: ButtonText;
      background: Canvas;
      color: CanvasText;

      &:focus-visible {
        outline-color: Highlight;
      }
    }
  }
}

autocomplete guides the browser about saved data such as name or email; list supplies suggestions from the document. They can coexist. autocomplete="off" does not make datalist a closed control or guarantee identical presentation. Preserve useful personal-data autofill; do not disable it routinely.

A custom combobox needs its own keyboard, focus, selection, and accessible announcement handling. Adding role="combobox" or a CSS-drawn popup does not provide this. Consider that complexity only when native controls cannot meet a specific need and you can verify it with assistive technology.

Common mistakes

Separate association failures, the data contract, and limitations of the native interface.

No suggestions appear

Expected result
The field finds the intended list and remains editable.
Cause
list uses #, points to the input id, repeats an id, or the type/browser does not offer that popup.
Solution
Check list → datalist id, unique IDs, and type support. Keep visible guidance and manual entry.

required allows a new value

Expected result
The interface contract matches what the server accepts.
Cause
A suggestion has been mistaken for a list of permitted values.
Solution
Use select or radios for a closed choice and validate the catalogue on the server.

The code is inserted instead of the name

Expected result
The final value is understandable and matches what the form needs.
Cause
The option separates value and label; choosing it inserts value.
Solution
Review the values and explain codes. Choose another pattern if you require a mandatory name-to-identifier mapping.

The popup ignores styling or is not announced

Expected result
People can complete the field without relying on that window.
Cause
The browser controls presentation, and zoom, contrast, and screen reader limitations exist.
Solution
Keep a persistent label and guidance. Test real combinations and offer another control when suggestions are essential.

Support and compatibility

API presence does not guarantee every type’s popup or a uniformly accessible experience.

On the review date, Web Platform DX and MDN classify datalist as Limited Availability: Firefox for Android retains a suggestion-menu limitation. Check each type too: text and email, dates/times, colours, and range ticks can show different interfaces or offer no suggestions.

For range, options may provide tick marks; min, max, and step still constrain the value. Do not rely on their labels being visible in every browser. For temporal and colour types, verify the real picker and expected value format before reusing a playground example.

MDN documents popup limitations: option text that does not scale with zoom, little high-contrast customisation, and reader/browser combinations that do not announce suggestions. Input CSS alone does not solve these issues. Test zoom, keyboard, mobile, and the assistive technology your audience uses.

If suggestions are unavailable, the input still allows manual entry according to its type. That is only a sufficient alternative when suggestions are optional and the value can be discovered another way. These scenes keep visible references where they help interpret values; they do not simulate support or install a polyfill.