The HTML <option> tag is used within a form for defining options in the drop-down list.
<!DOCTYPE html> <html> <head> <title>HTML option Tag</title> </head> <body> <form action = "/cgi-bin/dropdown.cgi" method = "post"> <select name = "dropdown"> <option value = "Java" selected>Java</option> <option value = "Ruby">Ruby</option> </select> <input type = "submit" value = "Submit" /> </form> </body> </html>
This will produce the following result −
This tag supports all the global attributes described in HTML Attribute Reference
The HTML <option> tag also supports the following additional attributes −
Attribute | Value | Description |
---|---|---|
disabled | disabled | Disables the input control. The button won't accept changes from the user. It also cannot receive focus and will be skipped when tabbing. |
label | text | Defines a label to use when using <optgroup>. |
selected | selected | Defines the default option to be selected when page loads. |
value | text | Specifies the value of the option to be sent to the server. |
This tag supports all the event attributes described in − HTML Events Reference
Chrome | Firefox | IE | Opera | Safari | Android |
---|---|---|---|---|---|
Yes | Yes | Yes | Yes | Yes | Yes |