×

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 Frames

Frames in Html is used to divide the browser into different sections where each section can load different Html documents. Collection of frame is known as Frameset. Creating frames:We use frameset...

2 minutes read.

HTML5 Formatting

HTML Formatting HTML Formatting is a method of text formatting for a better appearance and look. HTML allows us to format text without using the CSS. HTML includes a lot of formatting tags....

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.

HTML <script> Tag

For embedding a client -side script, we use script tag in html tag. This <script> tag can be used for containing scripting statements. It can also point another external script file...

2 minutes read.

HTML Hide Element

The HTML hide element is used to hide the element. We place the hidden attribute inside those elements which we want to hide. The hidden attribute is a Boolean attribute. The...

3 minutes read.

HTML Font Color

The HTML <font> tag has an attribute called color, which defines the color of the text. We use the color attribute inside the <font> tag to specify the color of...

6 minutes read.

HTML Canvas

HTML Canvas: Using JavaScript, the < canvas > tag in HTML is used for drawing graphics on web page. It can be used to draw routes, boxes, text, gradient, and...

3 minutes read.

Div Tag in HTML

In HTML, ‘div’ is a tag that specifies division or section in HTML document. But before going in detail of it, let’s first understand about tags in HTML. The tag...

8 minutes read.

HTML <sub> tag

The sub element in HTML is used to describe one or more subscript texts. If The sub tag shows the text which is presented in a smaller font and below...

2 minutes read.

How to change font in HTML

To give style to the content of your website, you may change the font of the text and make your website look attractive to the user. There are several methods which...

4 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.

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 <summary> tag

When we simply want to show the primary heading or topic name of hidden detailed material to users, then we can achieved this by using the summary tag. This makes it...

2 minutes read.

HTML <style> tag

The section of information that we want to style is contained in html style tag. It includes CSS, which is used to design the text and images in the web page. Syntax: <head> <title>…………....

3 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 Youtube

<object> element: It embed the object within the HTML documents and embed plug-ins such as Java applets, PDF readers, Flash Players etc in web pages. Example: <object width="100" height="100" data="bookmark.swf"></object> <embed> element: It defines an embedded...

1 minute read.

What is a Container tag?

In HTML, there are different types of tags or say instructions which make the developer specify various elements in the document and make the browsers understand what to display. Tags in...

5 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.

HTML Data Tag

HTML Data Tag: The HTML < data > tag is used to transmit its content to a machine-readable version. The data are presented in a particular format. It is useful...

3 minutes read.

HTML <svg> tag

SVG is used to determine the vector-based graphics in XML format. What is SVG? We utilize SVG tag to specify visuals for the website. The attribute of SVG in a HTML document...

2 minutes read.