Di dalam suatu daftar pilihan kadang berisi butir pilihan yang sudah dikelompokkan berdasarkan kriteria tertentu. Untuk mengelompokkan butir-butir pilihan tersebut anda bisa menggunakan elemen HTML bersama dengan elemen Show The above example shows typical 0 element nested inside the <select> .Each 0 element should have a attribute containing the data value to submit to the server when that option is selected. If no 3 attribute is included, the value defaults to the text contained inside the element. You can include a attribute on an 0 element to make it selected by default when the page first loads.The 8 to specify whether multiple options can be selected, and 9 to specify how many options should be shown at once. It also accepts most of the general form input attributes such as 0, 1, 2, etc.You can further nest 0 elements inside 4 elements to create separate groups of options inside the dropdown.For further examples, see . This element includes the global attributes. A string providing a hint for a user agent's autocomplete feature. See The HTML autocomplete attribute for a complete list of values and details on how to use autocomplete. This Boolean attribute lets you specify that a form control should have input focus when the page loads. Only one form element in a document can have the 2 attribute.This Boolean attribute indicates that the user cannot interact with the control. If this attribute is not specified, the control inherits its setting from the containing element, for example 9; if there is no containing element with the 1 attribute set, then the control is enabled.The 2 element to associate the <select> with (its form owner). The value of this attribute must be the of a 2 in the same document. (If this attribute is not set, the <select> is associated with its ancestor 2 element, if any.)This attribute lets you associate 2s anywhere in the document, not just inside a 2. It can also override an ancestor 2 element.This Boolean attribute indicates that multiple options can be selected in the list. If it is not specified, then only one option can be selected at a time. When 8 is specified, most browsers will show a scrolling list box instead of a single line dropdown.This attribute is used to specify the name of the control. A Boolean attribute indicating that an option with a non-empty string value must be selected. If the control is presented as a scrolling list box (e.g. when 8 is specified), this attribute represents the number of rows in the list that should be visible at one time. Browsers are not required to present a select element as a scrolled list box. The default value is 8.Note: According to the HTML specification, the default value for size should be 9; however, in practice, this has been found to break some websites, and no other browser currently does that, so Mozilla has opted to continue to return 8 for the time being with Firefox.On a desktop computer, there are a number of ways to select multiple options in a 8 attribute:Mouse users can hold the Ctrl, Command, or Shift keys (depending on what makes sense for your operating system) and then click multiple options to select/deselect them. Warning: The mechanism for selecting multiple non-contiguous items via the keyboard described below currently only seems to work in Firefox. On macOS, the Ctrl + Up and Ctrl + Down shortcuts conflict with the OS default shortcuts for Mission Control and Application windows, so you'll have to turn these off before it will work. Keyboard users can select multiple contiguous items by:
Keyboard users can select multiple non-contiguous items by:
The However, these properties don't produce a consistent result across browsers, and it is hard to do things like line different types of form element up with one another in a column. The For more useful information on styling
Also see the "Customizing select styles" example below for an example of you could attempt a simple The following example creates a very simple dropdown menu, the second option of which is selected by default.
The follow example is more complex, showing off more features you can use on a
You'll see that:
This example shows how you could use some CSS and JavaScript to provide extensive custom styling for a This example basically:
Note: Not all native features are supported, it's a Proof of Concept. IT starts from standard HTML but the same results can be achieved starting from JSON data, custom HTML, or other solutions. HTML
CSS
JavaScript
ResultContent categories, , , , , , and elementPermitted contentZero or more 0 or 4 elements.Tag omissionNone, both the starting and ending tag are mandatory.Permitted parentsAny element that accepts .Implicit ARIA roleid 3 with no 8 attribute and no 9 attribute greater than 1, otherwise id 6Permitted ARIA rolesid 7 with no 8 attribute and no 9 attribute greater than 1, otherwise no <label> 0 permittedDOM interface<label> 1 |