HTML Option Selected Attribute

Sameer Saini April 28, 2022
HTML Option Selected Attribute

In this blog post, we will learn about the Selected attribute in HTML Option element.

A dropdown list is created using the Select tag in HTML.

Inside the Select element, we have options of the dropdown which are created using the Option element.

By default, the first option element is selected.

But, what if we want to select some other option element in the select list?

Let's take a look at how we use the "Selected" attribute on option elements and select an option in a select list.

 

 

Select Option In Dropdown Using Selected Attribute

Let's create a dropdown for this example using the select element.

 

By default, the first option in the dropdown list is selected. In this example, you will see the option "Red" selected in the select list.

Select list with default option selected

 

Now, we will use the "Selected" attribute and select another option.

 

When we use the HTML option selected attribute, we set the option to be selected in the dropdown list.

 

Result:

Select list with option selected