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





Related Articles
What is HTML Form Elements HTML Form Elements
How to create HTML <input> Element HTML Form Elements
How to create The <label> Element HTML Form Elements
How to create HTML <select> Element HTML Form Elements
How to create HTML <option> element HTML Form Elements
How to Visible HTML Select Option Values HTML Form Elements
How to Allow Multiple Selection in HTML Option Value HTML Form Elements
How to create HTML <textarea> Element HTML Form Elements
How to create HTML <button> Element HTML Form Elements
How to create HTML <fieldset> and <legend> Elements HTML Form Elements
How to create HTML <datalist> Element HTML Form Elements
How to create HTML <output> Element HTML Form Elements

Single Articles
Simple Example of Option ElementHTML Form Elements
Full Example of Option ElementHTML Form Elements

Read Full:
HTML Form Elements
Category:
Web Tutorial
Sub Category:
HTML Form Elements
Uploaded by:
Admin
Views:
80


Reffered: https://www.w3schools.com/html/html_form_elements.asp