CSS Portal

HTML list Attribute

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
list
HTML AttributeBrowser support for this attribute varies across browsers.
Updated 28th March 2024

Description

The HTML list attribute is associated with the <input> element and is used to bind the input field to a <datalist> element. This association enables the creation of a predefined list of suggested values for the input field, enhancing user experience by providing an autocomplete feature. When users start typing in the input field, the browser displays a dropdown list of options that match the users' input, allowing them to select a suggested value instead of typing the entire value themselves. This is particularly useful for fields that have a limited set of possible values, such as country names, product names, or other categories.

The list attribute's value must be the same as the id attribute of the <datalist> element it is associated with. The <datalist> element contains a number of <option> elements, each representing a suggested value for the input field.

Here's a simple example of how to use the list attribute:

<input type="text" id="ice-cream-choice" name="ice-cream-choice" list="ice-cream-flavors" />
<datalist id="ice-cream-flavors">
  <option value="Chocolate">
  <option value="Coconut">
  <option value="Mint">
  <option value="Strawberry">
  <option value="Vanilla">
</datalist>

In this example, when the user starts typing in the input field, they will see a dropdown list of ice cream flavors to choose from. This not only speeds up the form filling process but also helps prevent typing errors and ensures the consistency of the input data.

Syntax

<input list="datalist-id">

Values

Applies To

Example

<input list="browsers" name="browser">
<datalist id="browsers">
<option value="Chrome">
<option value="Firefox">
<option value="Safari">
<option value="Edge">
</datalist>
Open in editor

Browser Support

The following information will show you the current browser support for the HTML list attribute. Hover over a browser icon to see the version that first introduced support for this HTML attribute.

Browser support for this attribute varies across browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee