×

Html <datalist >Tag

The autocomplete feature in HTML files is provided by the <datalist> tag. It can be used in conjunction with an input tag to enable users to quickly fill out form by selecting the data.

A value may be stored in the value and label attributes as well as the internal content of the <option> element. The drop-down menu's visibility depends on the browser, but no matter which option is selected. the control field's content always comes from the value attribute.

You have to provide the special identifier ‘id’ attribute in the <datalist> tag and add the value which is assigned in the list attribute of the <input> element. 

This behavior can differ from one browser to another and is only supported by specific types of "input".

Syntax
<datalist> Write Your List or Option Here  </datalist>

Example of Datalink Tag in Text form

When a user clicks or double-clicks on the control, suggested values for the types text, search, URL, tel, email, and number are displayed in a drop-down menu. The presence of predefined values is typically indicated by an arrow on the right side of the control.

<!DOCTYPE>
<html>  
<body>  
<label>  
 Enter your favourite Car:  <br />  
 <input type="text" id="favcar" list="favtcar">  
 <datalist id="favtcar">  
 <option value="Maruti 800">  
 <option value="Brezza">  
 <option value="Swift">   
 <option value="Accord">   
 <option value="Honda City">   
 <option value="Audi">   
 <option value="BMW">   
 <option value="Bentaly">   
 <option value="Jaquar ">   
 <option value="Ferarri">   
 <option value=" Rolls Royce">   
 <option value="Austo-Martin">  
 </datalist>  
</label>  
</body>  
</html>  

Output:

Html datalist Tag

Here, the HTML displays all the auto-suggested values beginning with the character "c" because the user has entered the value "c" in the input box. Additionally, we can also changed the option elements to show the auto-suggest feature based on the alphabet.

Html datalist Tag

Example of Datalink Tag in Date and Time Form

The types month, week, date, time, and Datetime-local may display an interface that enables to select simple date and time. The user can fill in the control value quickly by seeing predefined values there.

<!DOCTYPE>
<html>  
<body>  
<label>  
 Choose Your Perfect Time : <br />  
<input type="time" list="popularHours">
<datalist id="popularHours">
  <option value="12:00">
  <option value="13:00">
  <option value="14:00">
</datalist>
</body>
</html>

Output :

Html datalist Tag

Example of Datalink Tag in Range Form

The user can choose from a series of hash marks that are displayed as the range according to the suggested values.

<!DOCTYPE>
<html>  
<body>  
<label>  
 Choose Your Monthly Expenses Range: <br />  
<input type="range" list="tickmarks">
<datalist id="tickmarks">
  <option value="0">
  <option value="Rs.10,000">
  <option value="Rs. 20,000">
  <option value="Rs.30,000">
</datalist>
</body>
</html>

Output:

Html datalist Tag

Example of Datalink Tag in Color Form

The color type can display predefined colors in an interface offered by the browser.

<!DOCTYPE>
<html>  
<body>  
<label>  
 Choose Your Favourite Color  :  <br />  
<input type="color" list="redColors">
<datalist id="redColors">
  <option value="#800000">
  <option value="#8B0000">
  <option value="#A52A2A">
  <option value="#DC143C">
</datalist>
</body>
</html>

Output:

Html datalist Tag

Example Of Datalist With CSS

<!DOCTYPE html>
<html>
<head>
<style>
.cars {
height: 110px;
background-color: cadet blue;
width: 100%;
}
</style>
</head>
<body>
<div class = "cars" >
<label style = "font-size: x-large; font-weight: 500; margin-left: 20px " > Car Brand: </label >
<input list = "car_brands" name = "car brand" style = "margin-top: 40px; " >
<datalist id = "car_brands" >
<option value = "Aston Martin " >
<option value = "Audi " >
<option value = "Cadillac " >
<option value = "Chevrolet " >
<option value = "Honda " >
<option value = "Hyundai " >
<option value = "Chrysler " >
<option value = "Kia " >
</datalist>
</div>
</body>
</html>

Output :

Html datalist Tag

Attribute

The <datalist> tag only accepts Global Attributes. The <datalist> tag doesn't have any unique attributes.

Benefits of Datalist Tag

This datalist tag offers a feature that allows the user to pick and quickly enter data into the input field without having to type. It is helpful when an HTML form allowing the user to type into the field and then choose an option from the list.

Browser Compatibility

Chrome

Mozilla Firefox

Safari

Opera

Conclusion

The autocomplete feature in HTML files is provided by the <datalist> tag. It can be used in conjunction with an input tag to enable users to quickly fill out data form by selecting the data.

This datalist tag offers a feature that allows the user to pick the data and quickly enter data into the input field without having to type it in. It is helpful when an HTML form allowing the user to type into the field and to choose an option from the list.


Related Topics

HTML Search Box

The HTML search box is also known as the search bar. It is an input text field that is used to search the content. If the users want to explore...

7 minutes read.

HTML Anchor

HTML Anchor The HTML anchor tags define a hyperlink that links to other pages on one page. It can create hyperlinks to any web page and files, locations or any other...

3 minutes read.

HTML Headings

The titles and subtitles of our webpages are known as HTML headings. Let’s not talk about webpages but giving heading to almost everything like normal paragraphs, articles or let it...

2 minutes read.

Html &lt;Col> Tag

You can write the col tag inside the table tag after the thead, tbody, foot, and tr tags. You can also apply it after the caption tag (in which the...

4 minutes read.

HTML &lt;body> alink Attribute

HTML <body> alink Attribute What is HTML? The HTML or HyperText Markup Language is used to design web pages. The file extension name for HTML file is ".html". It was released in...

2 minutes read.

HTML Unordered List

In HTML, we have <ul> tag which defines the unordered list. And it is also known as bulleted list, because as we know it is not ordered list therefore it...

2 minutes read.

HTML <video> Tag

The Video tag in HTML is used to play video on a media player on the web page. We can also insert an audio by the video tag, but audio...

6 minutes read.

HTML Background Image

Inserting image in HTML An image (technically digital image) in HTML or even in general technical aspects, is a binary representation of visual information. By visual information we mean, in the...

8 minutes read.

How to add Google Translate Button on your Webpage?

Google translator is a multi-language translator used for translating the webpage. Google develops it. In today's digital age, it is essential because information is available worldwide in some specific language...

5 minutes read.

HTML Basic Tags

Heading Tags: This tag represents the document header. It is said to be a good practice if every document starts with Heading. Heading tags ranges from H1 to H6 i.e....

3 minutes read.

How to Create a Portfolio Gallery using HTML and CSS?

First, before starting this, the user should know some of the basics of HTML and CSS to create a portfolio gallery. To add more functionality to the website, we can also...

7 minutes read.

HTML <source> tag

For media attributes, such as <video> tag, <audio> tag, and <picture> tag, we use the <source> tag in html for adding such type of multiple media html elements in our...

4 minutes read.

Font tag in HTML

HTML stands for Hypertext Mark-up Language and is used to create web pages and other information that can be later displayed in a web browser. It also consists of a...

4 minutes read.

HTML <address> Tag

Hyper Text Markup Language, HTML is the best markup language for creating Web pages. HTML consists of a wide variety of elements. In all of these elements, one element is...

4 minutes read.

HTML <table> tag

The Table element If we want to show the data and information in a two-dimensional table with rows and columns, then we can achieve this by using the HTML element <table>. Syntax: <body> <table> <thead> <tr> <thcolspan="#">………….</th> </tr> </thead> <tbody> <tr> <td>……….</td> <td>……….</td> </tr> </tbody> </table> </body> Example: <!DOCTYPE...

9 minutes read.

HTML Forms

Forms are required when we want to collect data from the user. Html forms consists of different fields to take user inputs such as: input, text area, checkbox, password, radio...

4 minutes read.

HTML Text Format

Introduction HTML may format text in two different ways. The HTML tags define a text property to make it appear one way or another. A text element may also be formatted...

7 minutes read.

HTML <strong> tag

The strong element in HTML is used to display the real significant information in bold so that the user or reader will understand it easily. Syntax: <p> <strong>………… </strong> </p> Example Here, we will demonstrate how to...

2 minutes read.

HTML5 Tags

HTML5 Tags A list of newly included tags is provided in HTML5. These HTML 5 tags (elements) provide a better structure for the document. This list shows description of all HTML...

3 minutes read.

HTML Charsets

In this tutorial, we are going to discuss about the charsets in the HTML. The letters, numbers, and several other symbols are shown correctly by the web browser. All of this...

2 minutes read.