- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Difference between <datalist> and <select> tags in HTML
Both the <datalist> and <select> tags are typically used when selecting an item from a list. However, the key distinction between the two is that the <datalist> tag allows the user to add their own input as an option with the use of the <input> element, but the <select> tag does not offer this functionality.
Let's dive into the article to get a better understanding of the difference between the <datalist> and <select> tags in HTML.
HTML <datalist> tag
This tag specifies the predefined options for a <input> element. Additionally, the HTML <input> element receives the autocomplete feature from this tag. The user will see pre-defined alternatives beginning with the letter or word they have entered in the input element of the <datalist> tag. Note that the ID of the tag must match the <input> element attribute in order to use the <datalist> tag.
Syntax
Following is the syntax for HTML <datalist> tag
<datalist id="…."> <option value="…"> <option value="…."> </datalist>
Example
Following is the example where we are going to use the <datalist> tag.
<!DOCTYPE html> <html> <body style="background-color:#D5F5E3"> <label for="tutorial"> Select The Course: </label> <input list="tutorial" name="course" id="course"> <datalist id="tutorial"> <option value="HTML"> <option value="AI"> <option value="Cyber Security"> <option value="Big Data"> </datalist> <p style="color: #DE3163;"> Note:User Can Select The Option OR Enter Course On Their Own. </p> </body> </html>
On running the above code, the output window will pop up, displaying the input field on the webpage. When the user starts entering the input, it will provide a dropdown list to choose an option on his wish list, or else he can enter the input manually.
HTML <select> tag
This tag adds a drop-down menu list to a webpage, which is primarily utilized in the online forms that we all employ to gather user input. The <option> tag is part of the <select> tag and is used to display the drop-down list's options. The tag has several attributes, including <name>, <autofocus> and etc.
Syntax
Following is the syntax for HTML <select> tag
<select id="…"> <option value="..">text</option> <option value="…">text</option> </select>
Example
In the following example we are going to use the <select> tag.
<!DOCTYPE html> <html> <body style="background-color:#E8DAEF"> <label for="tutorial"> Choose The Car: </label> <select id="tutorial"> <option value="bmw">BMW</option> <option value="rs7">RS7</option> <option value="audi">AUDI</option> <option value="bugati">BUGATI</option> </select> </body> </html>
When the above code gets executed, it will generate an output consisting of user input along with a drop-down list on the webpage.
Difference between <datalist> and <select>
Let's look into the some of the key difference between <datalist> and <select> tag.
<datalist> tag |
<select> tag |
---|---|
The user has the option of selecting any item from the provided list or providing their own input. |
From the list of available options, the user may select just one. |
This tag is not a type of form input. |
This tag is a type of form input. |
The user can quickly submit a choice, receive suggestions, and then select one. |
To choose an option, the user has look through a lengthy list. |
The options list does not impose any limitations on the user. |
A user may only be given a limited number of alternatives. |
It offers auto-complete functionality. |
The auto-complete function is absent. |