Advertisement
Home Open Editor ❯

HTML <option> 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

<option selected>text</option>


Advertisement

Attribute Values

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