How to make a drop -down html list
Learn how to create a drop-down HTML list with this easy tutorial, complete with a step-by-step example.
Creating a drop-down list in HTML is a common task when building web forms. It allows users to select one option from a list of options presented in a drop-down menu. In this article, I will show you how to create a simple drop-down list using HTML.
To create a drop-down list in HTML, you will need to use the <select>
and <option>
tags. The <select>
tag creates the drop-down list, while the <option>
tag defines the options within the list.
Here is an example of a simple drop-down list with three options:
<select>
<option value="option1">Option 1</option>
<option value="option2">Option 2</option>
<option value="option3">Option 3</option>
</select>
In the example above, the <select>
tag creates the drop-down list, and the <option>
tags define the three options within the list. The value
attribute of the <option>
tag specifies the value that will be sent to the server when the form is submitted. The text between the opening and closing <option>
tags is the visible option text that the user will see in the drop-down list.
You can also add a default selected option by using the selected
attribute:
<select>
<option value="option1" selected>Option 1</option>
<option value="option2">Option 2</option>
<option value="option3">Option 3</option>
</select>
In this example, "Option 1" will be the default selected option when the drop-down list is initially displayed.
Additionally, you can use the disabled
attribute to disable certain options within the drop-down list:
<select>
<option value="option1">Option 1</option>
<option value="option2" disabled>Option 2</option>
<option value="option3">Option 3</option>
</select>
Using the <select>
and <option>
tags, you can create a simple drop-down list in HTML with various options and default selections. This allows users to easily select an option from a list when filling out a form on your website.