option ... ⁄option
HTML5 option element
The option element allows you to mark up an option within the select or datalist elements. »video
About option
Display & support option
- display in browser »video





Parents, children option
- option nested within elements »option parents
- elements nested within option »option children
»examples
Attributes option
- required: none
- optional: specific attributes, global attributes, event attributes
Observation: to have more than 1 option pre-selected (selected), multiple attribute on select parent element is required »video
Warning
option(s) selected versus option(s) pre-selected: see the difference »video
Syntax option
1 2 | <> ... </> <> ... » video |
Attributes and Values option (comma separated)
< | attribute | = | "attribute_value(s)" | > | Video | Examples |
---|---|---|---|---|---|---|
1. specific attributes | ||||||
1. | disabled | = | "", , disabled | »video | <disabled> ... <⁄ > | |
2. | label | = | string (option_label) | - | <label="option_label"> ...<⁄ > | |
3. | selected | = | "", , selected | »video | <selected> ... <⁄ > | |
4. | value | = | string (option_value) | - | <value="option_value"> ...<⁄ > | |
All Specific Attributes | ||||||
2. global attributes | ||||||
1. | accesskey | = | keyboard key | »img | <accesskey="h"> ... </ > | |
2. | class | = | class name | »html »img | <class="class_name"> ... </ > | |
3. | contenteditable | = | "", , true, false | »html | <contenteditable="true"> ... </ > | |
4. | contextmenu | = | menu id value | »html | <contextmenu="menu_id_value"> ... </ > | |
5. | data-* | = | value | - | <data-http-error="404"> ... </ > | |
6. | dir | = | ltr, rtl, auto | »html | <dir="ltr"> ... </ > | |
7. | draggable | = | true, , false | »img | <draggable="false"> ... </ > | |
8. | dropzone | = | copy, move, link, string:, file: | - | <dropzone="copy"> ... </ > | |
9. | hidden | = | "", , hidden | »html »img | <hidden="hidden"> ... </ > | |
10. | id | = | id name | »html »img | <id="unique_id_name"> ... </ > | |
11. | itemid | = | URL | - | - | |
12. | itemprop | = | string | »link »a | - | |
13. | itemref | = | string | - | - | |
14. | itemscope | = | "", , itemscope | - | - | |
15. | itemtype | = | absolute URL | - | - | |
16. | lang | = | language code | »html »head»title »img | <lang="en"> ... </ > | |
17. | spellcheck | = | "", , true, false | »html | <spellcheck="true"> ... </ > | |
18. | style | = | CSS property:value | »html »img | <style="color:red"> ... </ > | |
19. | tabindex | = | integer | »img | <tabindex="3"> ... </ > | |
20. | title | = | text | »html »link»style »abbr»dfn »img »meter | <title="html page"> ... </ > | |
21. | translate | = | "", yes, no | »html »img | <translate="yes"> ... </ > | |
All Global Attributes | ||||||
3. global event attributes | ||||||
1. | onclick | = | script | » list | <element onclick="script" > ... | |
2. | ondblclick | = | script | » list | <element ondblclick="script" > ... | |
All Event Attributes |
Video demonstration option element
HTML5 option element: mark up an option
min | video details |
---|---|
00:00 | video tutorial: option element |
00:05 | options element allows you to mark up an option An option can be: A) selected: if option element is child of select element or B) pre-selected: if option element is child of datalist element note: an option that can be selected can also be grouped together with other options under a common label |
00:11 | A) let's add options which can be selected (option element nested inside select element) |
00:37 | any option can be selected |
00:43 | the options can be grouped (option element nested inside optgroup element, inside select element) |
00:56 | the 3 options are grouped under 'Group x' which represents their common label |
01:02 | B) let's add options which can be suggested (option element nested inside datalist element) |
01:29 | as we type in, the list of suggestions display (= the options are being suggested to us) |
01:32 | options selected versus |
01:34 | options suggested |