How to set the default value for an HTML select element?

Spread the love

Sometimes, we want to set the default value for an HTML select element.

In this article, we’ll look at how to set the default value for an HTML select element.

How to set the default value for an HTML select element?

To set the default value for an HTML select element, we set the selected attribute.

For instance, we write

<option selected="selected">3</option>

to set the selected attribute of the option to selected so that the option is selected by default.

Conclusion

To set the default value for an HTML select element, we set the selected attribute.

Leave a Reply

Your email address will not be published. Required fields are marked *