Horje
How to create HTML <option> element

The <option> element defines an option that can be selected.

By default, the first item in the drop-down list is selected.

To define a pre-selected option, add the selected attribute to the option:


Simple Example of Option Element

<option value="fiat" selected>Fiat</option>

Full Example of Option Element

You can preselect an option with the selected attribute:
index.html
Example: HTML
<!DOCTYPE html>
<html>
<body>

<h2>Pre-selected Option</h2>

<p>You can preselect an option with the selected attribute:</p>

<form action="/action_page.php">
  <label for="cars">Choose a car:</label>
  <select id="cars" name="cars">
    <option value="volvo">Volvo</option>
    <option value="saab">Saab</option>
    <option value="fiat" selected>Fiat</option>
    <option value="audi">Audi</option>
  </select>
  <input type="submit">
</form>

</body>
</html>

Output should be:

Full Example of Option Element





Category:
Web Tutorial
Sub Category:
HTML Form Elements
Uploaded by:
Admin


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