Horje
HTML selected Attribute

Definition and Usage

The selected attribute is a boolean attribute.

When present, it specifies that an option should be pre-selected when the page loads.

The pre-selected option will be displayed first in the drop-down list.

Tip: The selected attribute can also be set after the page loads, with a JavaScript.


Applies to

The selected attribute can be used on the following element:

Element Attribute
<option> selected

Browser Support


How to add A drop-down list with a pre-selected option - HTML selected Attribute

The option selected attribute.
index.html
Example: HTML
<!DOCTYPE html>
<html>
<body>

<h1>The option selected attribute</h1>

<label for="cars">Choose a car:</label>

<select id="cars">
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="vw">VW</option>
  <option value="audi" selected>Audi</option>
</select>

</body>
</html>

Output should be:

How to add A drop-down list with a pre-selected option - HTML selected Attribute




html selected attribute

Type:
Develop
Category:
Web Tutorial
Sub Category:
HTML Attribute
Uploaded by:
Admin


Read Article
https://develop.horje.com/learn/1434/reference