You are here: Reference > HTML > attributes > SELECTED (option)

SELECTED attribute (option)

Browser support:
Specifies the initial state of an option element.
The select element allows simple or multiple selection, depending on the state of the MULTIPLE attribute.
  • If multiple selection is allowed, the visual appearance of the selection list can only be a list box.
  • If only one selected element is allowed, the selection list may be a drop-down list or a list box. The default appearance is the drop-down list.
You can set the count of the visible rows in a selection list with the size attribute.
If the value of the size attribute is greater than one, the appearance of the selection list is a list box.
In a non-empty drop-down list always exactly one selected element exists. If there is no element selected by default in a drop-down list, the first option will be selected.
In a single-selection list box the count of the selected items can be 0 (if the list box has no selected element by default) or 1.
In a multiple-selection list box the count of the selected items may range from 0 to the number of the items.
JavaScript page for this attribute: selected. You can find other example(s) there.

Possible values:

This attribute has no values.
Specifying the SELECTED attribute with an arbitrary value has the same effect as specifying it with no value.
For example, all of the following declarations have the same effect: selected, selected="true", selected="false", selected="on", selected="selected".
Although Boolean attributes may be used with no value in HTML, for XHTML compatibility, always use the SELECTED attribute in the following format: selected="selected".

Example HTML code 1:

This example illustrates the use of the SELECTED attribute in a single-selection list:
<select>
    <option value="Apple" />Apple
    <option value="Pear" />Pear
    <option value="Peach" selected="selected" />Peach
</select>
Did you find this example helpful? yes no

Example HTML code 2:

This example illustrates the use of the SELECTED attribute in a multiple-selection list:
<select multiple="multiple" size="3">
    <option value="Apple" selected="selected" />Apple
    <option value="Pear" />Pear
    <option value="Peach" selected="selected" />Peach
</select>
Did you find this example helpful? yes no

Supported by tags:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content