user7025447 user7025447 - 11 months ago 44
HTML Question

How to set default value of option in HTML?

, I know we can set default option value by using

in option's attribute.

But Is there any way to set a default value of option from attribute in select tag . i.e when i open page that value should be selected itself , and i want to do this in select tag

Something like this

<select selected= "saab">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="vw">VW</option>
<option value="audi" >Audi</option>

Answer Source

No. The only way, in HTML, to set the default option is to use the selected attribute on the option.

This avoids the need to provide id attributes for options (given that multiple options can share the same value) and it also because a select element can have multiple options selected at the same time (if the multiple attribute is set).