Thanks to visit codestin.com
Credit goes to www.cssportal.com

CSS Portal

HTML selected Attribute

If this site has been useful, we’d love your support! 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

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 information will show you the current browser support for the HTML selected attribute. Hover over a browser icon to see the version that first introduced support for this HTML attribute.

This attribute is supported by all modern browsers.
Desktop
Chrome
Edge
Firefox
Opera
Safari
Tablets & Mobile
Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-

Last updated by CSSPortal on: 29th March 2024

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!