HTML Dropdown List
In HTML, a dropdown list is a form element that allows users to select one option from a list of predefined options.
Dropdown list is created using HTML <select>
element.
Options of the dropdown list are created using HTML <option>
element.
How to Create a Dropdown List
Create an HTML <select>
element as shown in the example.
Add five HTML <option>
elements inside the HTML <select>
element.
Add "Python Language", "C# Language", "Java Language", "C++ Language", and "C Language" repectively to the 5 options. The texts will be displayed as selection options in the dropdown list.
Have a closer look at the code and its output:
Example of Dropdown List
Output of the above code example
Example of Dropdown List in a Webpage
Select a programming language
Now you can select an option from the dropdown list.
Add Value Attributes to the Dropdown Options
Create an HTML form element and add the select element inside the form.
If you do not add value to the option, the option text will be treated as value of the option.
Sometime, it is necessary to add value
attribute to the <option>
opening tag for form submission.
Add "Python", "C#", "Java", "C++", and "C" as values to the value
attributes of options as shown in the following example.
The value attribute specifies the value that will be submitted when the form is submitted.