Advertisement
Home Open Editor ❯

HTML selected Attribute

Example

<label for="lang">Choose a language:</label>

<select id="lang">
  <option value="HTML">HTML</option>
  <option value="CSS" selected>CSS</option>
  <option value="JavaScript">JavaScript</option>
</select>

Try this code ❯

Meaning

The selected attribute specifies that the associated item is the default selection.

If this attribute is not included, the first item in the selection list is the default.

Note: It should occur in only one entry. Under XHTML, the value of the selected attribute must be set to selected(selected="selected").


Standard Syntax

HTML: <element selected>
XHTML: <element selected="selected">


Applies to:

The selected attribute can be used on the following element:

Element Attribute
<option> selected

Advertisement

Attribute Values

Value Description
selected It's optional but mandatory in XHTML.
Home Open Editor ❯
Advertisement