How can I set the default value for an HTML <select> element?

Jichao picture Jichao · Aug 19, 2010 · Viewed 2.7M times · Source

I thought that adding a "value" attribute set on the <select> element below would cause the <option> containing my provided "value" to be selected by default:

However, this did not work as I had expected. How can I set which <option> element is selected by default?

Answer

Borealid picture Borealid · Aug 19, 2010

Set selected="selected" for the option you want to be the default.

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