Open In App
Related Articles

Difference between <datalist> & <select> tags in HTML

Improve Article
Improve
Save Article
Save
Like Article
Like

In this article, we’ll be differentiating the two tags: <datalist> and <select> tag. Generally, both the tags are used for choosing an option from the given list. But the main difference between both is that in the <datalist> tag the user can enter its own input and add that as an option with the help of the <input> element whereas the <select> tag doesn’t provide this feature.

HTML <datalist> tag: This tag specifies the predefined options for an <input> element. This tag also gives the autocomplete feature for the <input> element of HTML. Like once the user starts typing the input element of <datalist> tag, the user will see the pre-defined options starting with the letter or word typed by the user. Note that to use the <datalist> tag, the id of the tag must be the same as of the <input> element attribute.

Syntax:

<datalist id="courses">
   <option value="DSA">
   <option value="ML and AI">
</datalist>

Example: In this example, we will see the use of <datalist>

HTML




<!DOCTYPE html>
<html>
 
<body>
    <h1>GeeksforGeeks</h1>
    <h3>Using Datalist</h3>
    <label for="courses">
        Choose your favorite course from the list:
    </label>
     
    <input list="courses" name="course" id="course">
     
    <datalist id="courses">
        <option value="Java">
        <option value="C++">
        <option value="Python">
        <option value="DSA">
        <option value="ML and AI">
    </datalist>
 
    <p style="color: gray;">
        User can choose an option from a
        given options <br>and also give
        an input and filter values from
        the option list.
    </p>
</body>
</html>


Output:

HTML <select> tag: This tag creates a drop-down menu list in a webpage that is mostly used in the online forms that we all use for collecting the user input. The <select> tag contains <option> tag to display the list of available options from the drop-down list. The tag has various attributes that include <name>, <autofocus>, etc.

Syntax:

<select id="courses">
   <option value="Java">Java</option>
   <option value="C++">C++</option>
</select>

Example: In this example, we will see the use of <select> tag

HTML




<!DOCTYPE html>
<html>
 
<body>
    <h1>GeeksforGeeks</h1>
    <h3>Using Select</h3>
 
    <label for="courses">
        Choose your favorite
        course from the list:
    </label>
    <select id="courses">
        <option value="Java">Java</option>
        <option value="C++">C++</option>
        <option value="Python">Python</option>
        <option value="DSA">DSA</option>
        <option value="ML and AI">ML and AI</option>
    </select>
    <p style="color: gray;">
        User has to choose any
        one option from a list.
    </p>
</body>
</html>


Output:

Differences Between <datalist> and <select> tag

<select> tag

<datalist> tag

The user can choose only one option from the given list. The user can choose any option from the given list but can also use its own input.
This tag is a form input type. This tag is not a form input type.
The user has to scan a long list so as to select an option.  The user can easily input the option and get the hints and then can be chosen by the user.
The user can be restricted to a list of options. The user is not restricted by the list of options.
It doesn’t provide the auto-complete feature. It provides the auto-complete feature.

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 09 May, 2023
Like Article
Save Article
Previous
Next
Similar Reads
Complete Tutorials