html tutorial - <option> Option Tag in HTML - html5 - html code - html form



option tag in html

Learn html - html tutorial - option tag in html - html examples - html programs

  • The <option> tag specifies an option in a select list.
  • <option> tag can be used inside a <select> or <datalist> element.
  • The <option> tag supports Global Attributes and Event Attributes.

Syntax for <option> tag:

<option value =”text”>content</option>

Sample Coding for <option> tag in HTML:

Tryit<!DOCTYPE html>
<html >
    <body>
        <select>
            <option value="css">Wikitechy CSS</option>
            <option value="html">Wikitechy HTML</option>
            <option value="java">Wikitechy JAVA</option>
            <option value="c">Wikitechy C</option>
        </select>
    </body>
</html>

Code Explanation for <option> tag:

<option> Tag Code Explanation

  1. <option> tag is used to described an option in a select list.
  2. value is an attribute, which described the value to be sent to a server.

Output for <option> tag:

<option> Tag Output

  1. The options CSS, HTML, JAVA, C has been shown in a drop-down.

Attributes of <option> tag:

Attribute Value HTML4 HTML5 Description
label disabled Yes Yes Describes a small label for an option.
disabled text Yes Yes Defines if an option should not be shown.
value selected Yes Yes Describes the value to be gone to a server.
selected text Yes Yes Indicates if an option have been pre-selected during the page loads.

Browser Support for <option> tag:

Yes Yes Yes Yes Yes

Tips and Notes

  • The <option> tag is used without any attributes, though the value attribute is needed, that shows what is gone to the server.
  • Whenever we have a lengthy list of options, we can groups of similar options with the <optgroup> tag.

Related Searches to option tag in html