Computer >> Computer tutorials >  >> Programming >> HTML

How to include an option in a drop-down list in HTML?


To include an option in a drop-down list, use the <option> tag in HTML. The HTML <option> tag is used within a form for defining options in the drop-down list.

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

Example

You can try to run the following code to implement <option> element in HTML −

<!DOCTYPE html>
<html>
   <head>
      <title>HTML option Tag</title>
   </head>
   <body>
      <form action = "/cgi-bin/dropdown.cgi" method = "post">
         <select name = "dropdown">
            <option value = "HTML" selected>HTML</option>
            <option value = "Ruby">Ruby</option>
         </select>
         <input type = "submit" value = "Submit" />
      </form>
   </body>
</html>