- HTML Tutorial
- HTML - Home
- HTML - History and Evolution
- HTML - Overview
- HTML - Editors
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Headings
- HTML - Paragraphs
- HTML - Quotations
- HTML - Comments
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Style Sheet
- HTML - CSS Classes
- HTML - CSS IDs
- HTML - Images
- HTML - Image Map
- HTML Tables
- HTML - Tables
- HTML - Headers & Caption
- HTML - Table Styling
- HTML - Table Colgroup
- HTML - Nested Tables
- HTML Lists
- HTML - Lists
- HTML - Unordered Lists
- HTML - Ordered Lists
- HTML - Definition Lists
- HTML Links
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Iframes
- HTML - Blocks
- HTML Backgrounds
- HTML - Backgrounds
- HTML Colors
- HTML - Colors
- HTML - RGB
- HTML - HEX
- HTML - HSL
- HTML Forms
- HTML - Forms
- HTML - Form Attributes
- HTML - Form Control
- HTML - Input Attributes
- HTML Media
- HTML - Video Element
- HTML - Audio Element
- HTML - Embed Multimedia
- HTML Header
- HTML - Head Element
- HTML - Adding Favicon
- HTML - Javascript
- HTML Layouts
- HTML - Layouts
- HTML - Layout Elements
- HTML - Layout using CSS
- HTML - Responsiveness
- HTML - Symbols
- HTML - Emojis
- HTML - Style Guide
- HTML Graphics
- HTML - SVG
- HTML - Canvas
- HTML APIs
- HTML - Geolocation API
- HTML - Drag & Drop API
- HTML - Web Workers API
- HTML - WebSocket
- HTML - Web Storage
- HTML - Server Sent Events
- HTML Miscellaneous
- HTML - MathML
- HTML - Microdata
- HTML - IndexedDB
- HTML - Web Messaging
- HTML - Web CORS
- HTML - Web RTC
- HTML Demo
- HTML - Audio Player
- HTML - Video Player
- HTML - Web slide Desk
- HTML Tools
- HTML - Velocity Draw
- HTML - QR Code
- HTML - Modernizer
- HTML - Validation
- HTML - Color Code Builder
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
- HTML Resources
- HTML - Quick Guide
- HTML - Useful Resources
- HTML - Color Code Builder
- HTML - Online Editor
HTML - <option> Tag
The <option> tag defines either the elements of the data list for autocomplete, specified by the <datalist> tag, or the items of a drop-down list, defined by the <select> tag. The <select> tag, <datalist> tag, or <optgroup> tag, which organizes the list items, can employ the <option> tag as a child element. If the data lists need to be delivered to the server or if scripts need to access the data lists, the <option> tag is added to the <form> tag.
Syntax
Following is the syntax for HTML <option> tag −
<option>.......</option>
Specific Attributes
The HTML <output > tag also supports the following additional attributes −
S.No. | Attribute & Description |
---|---|
1 | 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. |
2 | label Defines a label to use when using <optgroup>. |
3 | selected Defines the default option to be selected when page loads. |
4 | value Specifies the value of the option to be sent to the server. |
Example
In the following program, we are using the HTML <option> tag to define the item contained in a "select" element in an HTML.
<!DOCTYPE html> <html lang="en"> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>HTML option tag</title> </head> <body> <!--create an option tag--> <select name="" id=""> <option value="">Choose your option</option> <option value="html">HTML</option> <option value="css">CSS</option> <option value="javascript">JavaScript</option> </select> </body> </html>
When we run the above code, it will generate an output consisting of the dropdown menu displayed on the webpage.
Example
Following is another example of the HTML <option> tag. Here, we are using the "option" element(tag) to define an item contained in a "datalist" element in an HTML.
<!DOCTYPE html> <html lang="en"> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>HTML option tag</title> </head> <body> <!--create an option tag--> <p>The "option" tag with the "datalist" element</p> <input type="text" list="colors"> <datalist id="colors"> <option value="red"></option> <option value="blue"></option> <option value="green"></option> <option value="yellow"></option> </datalist> </body> </html>
On running the above code, the output window will pop up displaying the option tag used in the datalist element on the webpage.
Example
In this program, we are creating an HTML <option> tag to define an item contained in an "outgroup" element in an HTML.
<!DOCTYPE html> <html lang="en"> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>HTML option tag</title> </head> <body> <!--create an option tag--> <p>The "option" tag with "select" and "optgroup" element</p> <select> <optgroup label="Colors"> <option value='red'>Red</option> <option value="green">Green</option> <option value="yellow">Yellow</option> <option value="blue">Blue</option> </optgroup> <optgroup label="Fruits"> <option value="apple">Apple</option> <option value="banana">Banana</option> <option value="orange">Orange</option> <option value="grapes">Grapes</option> </optgroup> </select> </body> </html>
When we run the above code, it will generate an output consisting of the dropdown menu displayed on the webpage.
Example
In this example, we are creating an HTML <option> tag to define an item contained in a "select" element. Then, we are using the "disabled" attribute to disable the option. Using CSS, we are styling the option tag.
<!DOCTYPE html> <html lang="en"> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>HTML option tag</title> <style> select { width: 200px; } option { background-color: rgb(141, 141, 141); color: blue; } </style> </head> <body> <!--create an option tag--> <p>The "option" tag with "select" element</p> <select> <option value='red' disabled>Red</option> <option value="green">Green</option> <option value="yellow">Yellow</option> <option value="blue">Blue</option> </select> </body> </html>
On running the above code, the output window will pop up displaying the dropdown menu applied with CSS and used with a disabled attribute on the webpage.