HTML selected attribute

HTML selected attribute selects one option out of many options by default.


<p>This attribute gives the default or initial value to the select element.</p>
<p>If you are given a chance to visit one of the following countries,then what will be your choice?</p>
 <option selected>Algeria
Try </>

In the above example, the Algeria option is selected instead of Russia i.e. the user sees the Algeria option initially.

selected attribute value

selected attribute is a boolean type attribute. The presence of this attribute selects one option in an options list.

By default the value of the selected attribute is false. The value can be set to true by writing the selected attribute in the respective option element.

Related Tags

<option> tag

option tag defines one option. If selected attribute is used in more than one options elements in an options list, then last option having the selected attribute will be selected.


 <option selected>China
 <option selected>Australia

In the above example, although selected attribute is used in two options but the last one will be selected (i.e. Australia).

This attribute should be used only once in an option list.

Was this article helpful?




Get the newsletter