w3-video.com logo

HTML5 Tutorial

Home HTML5 XAMPP .htaccess Firefox Notepad++

Share it



option selected attribute

The selected attribute on the option element:

Warning: in order to have multiple pre-selected options, multiple attribute on select parent element is required.

Examples

<optionattribute="value(s)">...<⁄option>example
3.selected= "",  , selected<option selected> ... <⁄option>
<option selected=""> ... <⁄option>
<option selected="selected"> ... <⁄option>

Video demonstration option selected attribute

HTML5 option selected attribute Tutorial

min video details
00:00 video tutorial: selected attribute on option element
00:05 selected attribute on option element pre-selects the option (is an optional attribute)
00:15 let's make the 3rd option pre-selected, by adding the selected attribute on it
00:15 Attribute values:
- no value: attribute's minimized form: <option selected>
- value empty string: <option selected="">
- value = attribute's canonical name: <option selected="selected">
00:27 option C has been pre-selected
00:32 in order to have more than 1 option pre-selected, multiple attribute on select element is required
00:41 test result ok:
multiple attribute on select element is missing → multiple options can't be pre-selected despite the selected attribute added on 2 options
00:44 adding the multiple attribute on select element (multiple attribute allows multiple options to be (pre)-selected at once)
00:51 test result ok:
multiple attribute on select element is present → multiple options can be pre-selected and have been pre-selected: option A and option C
00:56 the text color of a selected ⁄ preselected option(s) is white on a blue background
option intro option optional, occurrences option browser display option parents - children option(s) selected vs pre-selectedoption syntaxoption disabled attribute