CodesJava

Easy learning with example program codes

Option HTML

HTML <option> Tag

Within a <select> or <datalist> element, we can define options in a dropdown list using the HTML <option> tag. Each dropdown list in HTML contains at least one <option> element.

Syntax:

<option value="">.....</option>

Example:

<!DOCTYPE html>
<html>
<body>
<h3> Select an Option:</h3>
<select>
    <option value="Apple">Apple</option>
    <option value="Mango">Mango</option>
    <option value="Pineapple">Pineapple</option>
    <option value="Papaya">Papaya</option>
</select>
</body>
</html>

Output 1:

Output 2:

Explanation:

In the above example, we are using the HTML <option> tag to add options to a dropdown list.

Tag specific attributes:

AttributeValueUses
disableddisabledUsed to disable an option.
labeltextUsed to specify the name for the list item.
selectedselectedUsed to pre-select an option, when the page loads.
valuetextUsed to define the value which is sent to the server.

Global attributes:

The HTML global attributes are supported by the HTML <option> tag.

Event attributes:

The HTML event attributes are supported by the HTML <option> tag.

Supporting Browsers:

Chrome, IE, Firefox, Opera and Safari.

Please follow and like us:
error
Posted in HTML   









Copyright © 2019 CodesJava DMCA.com Protection Status