Questa traduzione è incompleta. Collabora alla traduzione di questo articolo dall’originale in lingua inglese.
The HTML <option>
element is used to define an item contained in a <select>
, an <optgroup>
, or a <datalist>
element. As such, <option>
can represent menu items in popups and other lists of items in an HTML document.
Categoria | None. |
---|---|
Contenuto permesso | Text, possibly with escaped characters (like é ). |
Omissione dei tag | The start tag is mandatory. The end tag is optional if this element is immediately followed by another <option> element or an <optgroup> , or if the parent element has no more content. |
Elementi genitore permessi | A <select> , an <optgroup> or a <datalist> element. |
Regole ARIA permesse | Nessuna |
Interfaccia DOM | HTMLOptionElement |
Attributi
Questo elemento include gli attributi globali.
disabled
- If this Boolean attribute is set, this option is not checkable. Often browsers grey out such control and it won't receive any browsing event, like mouse clicks or focus-related ones. If this attribute is not set, the element can still be disabled if one of its ancestors is a disabled
<optgroup>
element. label
- This attribute is text for the label indicating the meaning of the option. If the
label
attribute isn't defined, its value is that of the element text content. selected
- If present, this Boolean attribute indicates that the option is initially selected. If the
<option>
element is the descendant of a<select>
element whosemultiple
attribute is not set, only one single<option>
of this<select>
element may have theselected
attribute. value
- The content of this attribute represents the value to be submitted with the form, should this option be selected. If this attribute is omitted, the value is taken from the text content of the option element.
Esempi
See <select>
for examples.
Specifications
Specification | Status | Comment |
---|---|---|
HTML Living Standard The definition of '<option>' in that specification. |
Living Standard | |
HTML5 The definition of '<option>' in that specification. |
Recommendation | |
HTML 4.01 Specification The definition of '<option>' in that specification. |
Recommendation | Initial definition |
Compatibilità browser
Feature | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | 1 | Yes | 1 | Yes | Yes | Yes |
disabled | 1 | Yes | 1 | Yes | Yes | Yes |
label | 1 | Yes | 11 2 3 | Yes | Yes | Yes |
selected | 1 | Yes | 1 | Yes | Yes | Yes |
value | 1 | Yes | 1 | Yes | Yes | Yes |
Feature | Android webview | Chrome for Android | Edge mobile | Firefox for Android | Opera Android | iOS Safari | Samsung Internet |
---|---|---|---|---|---|---|---|
Basic support | Yes | Yes | Yes | 4 | Yes | Yes | Yes |
disabled | Yes | Yes | Yes | 4 | Yes | Yes | Yes |
label | Yes | Yes | Yes | 41 | Yes | Yes | Yes |
selected | Yes | Yes | Yes | 4 | Yes | Yes | Yes |
value | Yes | Yes | Yes | 4 | Yes | Yes | Yes |
1. Firefox doesn't display the value of the label
attribute as option text if element's content is empty. See bug 40545.
2. Historically, Firefox has allowed keyboard and mouse events to bubble up from the <option>
element to the parent <select>
element, although this behavior is inconsistent across many browsers. For better Web compatibility (and for technical reasons), when Firefox is in multi-process mode and the <select>
element is displayed as a drop-down list. The behavior is unchanged if the <select>
is presented inline and it has either the multiple
attribute defined or a size
attribute set to more than 1
. Rather than watching <option>
elements for events, you should watch for change events on <select>
. See bug 1090602 for details.
3. When Mozilla introduced dedicated content threads to Firefox (through the Electrolysis, or e10s, project), support for styling <option>
elements was removed temporarily. Starting in Firefox 54, you can apply foreground and background colors to <option>
elements again, using the color
and background-color
CSS properties. See bug 910022 for more information. Note that this is still disabled in Linux due to lack of contrast (see bug 1338283 for progress on this).
See also
- Other form-related elements:
<form>
,<legend>
,<label>
,<button>
,<select>
,<datalist>
,<optgroup>
,<fieldset>
,<textarea>
,<keygen>
,<input>
,<output>
,<progress>
and<meter>
.