HTML selected Attribute

If this site has been useful, we’d love your support! Running this site takes time and resources, and every small contribution helps us keep creating valuable content. Consider buying us a coffee to keep things going strong!

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
Edge Chrome Firefox Opera Safari
1211154
Tablets / Mobile
Chrome Firefox Opera Safari Samsung Webview
184143.214.4

Last updated by CSSPortal on: 29th March 2024