HTML | option Tag

The <option> tag in HTML is used to choose an option from a Drop-Down menu. This tag can be used with or without any attributes and needed value can be sent to the server.
The group of options can be created using <optgroup> Tag. It creates the group of related menu items.

Syntax:

<option> Contents... </option>

Attributes: The <option> tag contains four attributes which are listed below:



  • disabled: This attribute contains the value disabled which represents option is disabled.
  • label: This attribute contains the text value which represents the shorted label for option.
  • selected: This attribute contains the value selected which represents the item is per-selected when browser loaded.
  • value: This attribute contains the value text which sent to the server.

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
    <head>
        <title>option tag</title>
        <style>
            body {
                text-align:center;
            }
            h1 {
                color:green;
            }
        </style>
    </head>
    <body>
        <h1>GeeksforGeeks</h1>
        <h2><option> Tag</h2>
        <select>
            <option>Choose an option</option>
            <option value="html">HTML</option>
            <option value="java">JAVA</option>
            <option value="C++">C++</option>
            <option value="php">PHP</option>
            <option value="perl">PERL</option>
        </select>
    </body>
</html>                    

chevron_right


Output:

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
    <head>
        <title>option tag</title>
        <style>
            body {
                text-align:center;
            }
            h1 {
                color:green;
            }
        </style>
    </head>
    <body>
        <h1>GeeksforGeeks</h1>
        <h2><option> Tag</h2>
        <strong>Select City<br></strong>
        <select>
            <option>Allahabad</option>
            <option>Pryagraj</option>
            <option>Jaipur</option>
            <option>Noida</option>
        </select>
    </body>
</html>                    

chevron_right


Output:

Supported Browsers: The browser supported by <option> tag are listed below:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Safari
  • Opera


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.