HTML selected Attribute
Description
The selected
attribute is a boolean attribute used in HTML to pre-select an option within a <select>
element. When an <option>
element within a <select>
dropdown list has the selected
attribute, it means that this particular option will be displayed as the default choice when the page first loads. This attribute is particularly useful for forms where a default value should be chosen based on certain conditions or for enhancing the user experience by highlighting a commonly selected option.
The selected
attribute does not require a value; merely including the word selected
within the <option>
tag is sufficient to activate its functionality. However, for XHTML compatibility, it is often written as selected="selected"
. Note that in a <select>
element without the multiple
attribute, only one option can be marked as selected
. If multiple options are marked, the last one in the HTML source will be shown as selected.
Syntax
<option selected>
Values
The selected
attribute is a boolean attribute, therefore no values are associated with this attribute.
Applies To
The selected
attribute can be used on the following html elements.
Example
<select name="cars">
<option value="Mercedes">Mercedes</option>
<option value="Lamborghini">Lamborghini</option>
<option value="Jaguar" selected>Jaguar</option>
<option value="BMW">BMW</option>
<option value="Audi">Audi</option>
</select>
Browser Support
The following table will show you the current browser support for the HTML selected
Attribute.
Desktop | |||||
12 | 1 | 1 | 15 | 4 |
Tablets / Mobile | |||||
18 | 4 | 14 | 3.2 | 1 | 4.4 |
Last updated by CSSPortal on: 29th March 2024