How to set the default value for an HTML select element

If you are looking for how can I set the value for an HTML <select> element, then after reading this article, you can easily do that.

We have a select element with some options. By default, the first option is set as a default value. But, the default value of the select element can be set by using the selected attribute.

The selected attribute is a boolean attribute.
set default value for select element
     <option>option 1</option>
     <option>option 2</option>
     <option selected>option 3</option>
     <option>option 4</option>
Try it Yourself »