[go: up one dir, main page]

      1. 4.10.6 The button element
      2. 4.10.7 The select element
      3. 4.10.8 The datalist element
      4. 4.10.9 The optgroup element
      5. 4.10.10 The option element
      6. 4.10.11 The textarea element
      7. 4.10.12 The output element
      8. 4.10.13 The progress element
      9. 4.10.14 The meter element
      10. 4.10.15 The fieldset element
      11. 4.10.16 The legend element

4.10.6 The button element

HTML element is an interactive element activated by a user with a mouse, keyboard, finger, voice command, or other assistive technology. Once activated, it then performs an action, such as submitting a form or opening a dialog.">Element/button

Support in all current engines.

Firefox1+Safari4+Chrome1+
Opera15+Edge79+
Edge (Legacy)12+Internet ExplorerYes
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android14+
Categories:
Flow content.
Phrasing content.
Interactive content.
Listed, labelable, submittable, and autocapitalize-and-autocorrect inheriting form-associated element.
Palpable content.
Contexts in which this element can be used:
Where phrasing content is expected.
Content model:
Phrasing content, but there must be no interactive content descendant and no descendant with the tabindex attribute specified.
Tag omission in text/html:
Neither tag is omissible.
Content attributes:
Global attributes
command — Indicates to the targeted element which action to take.
commandfor — Targets another element to be invoked.
disabled — Whether the form control is disabled
form — Associates the element with a form element
formactionURL to use for form submission
formenctypeEntry list encoding type to use for form submission
formmethod — Variant to use for form submission
formnovalidate — Bypass form control validation for form submission
formtargetNavigable for form submission
name — Name of the element to use for form submission and in the form.elements API
popovertarget — Targets a popover element to toggle, show, or hide
popovertargetaction — Indicates whether a targeted popover element is to be toggled, shown, or hidden
type — Type of button
value — Value to be used for form submission
Accessibility considerations:
For authors.
For implementers.
DOM interface:
Uses HTMLButtonElement.

The button element represents a button labeled by its contents.

The element is a button.

The type attribute controls the behavior of the button when it is activated. It is an enumerated attribute with the following keywords and states:

Keyword State Brief description
submit Submit Button Submits the form.
reset Reset Button Resets the form.
button Button Does nothing.

The attribute's missing value default and invalid value default are both the Auto state.

A button element is said to be a submit button if any of the following are true:

Constraint validation: If the element is not a submit button, the element is barred from constraint validation.

If specified, the commandfor attribute value must be the ID of an element in the same tree as the button with the commandfor attribute.

The command attribute is an enumerated attribute with the following keywords and states:

Keyword State Brief description
toggle-popover Toggle Popover Shows or hides the targeted popover element.
show-popover Show Popover Shows the targeted popover element.
hide-popover Hide Popover Hides the targeted popover element.
close Close Closes the targeted dialog element.
show-modal Show Modal Opens the targeted dialog element as modal.
A custom command keyword Custom Only dispatches the command event on the targeted element.

The attribute's missing value default and invalid value default are both the Unknown state.

A custom command keyword is a string that starts with "--".

The form attribute is used to explicitly associate the button element with its form owner. The name attribute represents the element's name. The disabled attribute is used to make the control non-interactive and to prevent its value from being submitted. The formaction, formenctype, formmethod, formnovalidate, and formtarget attributes are attributes for form submission.

The formnovalidate attribute can be used to make submit buttons that do not trigger the constraint validation.

The formaction, formenctype, formmethod, formnovalidate, and formtarget must not be specified if the element is not a submit button.

The commandForElement IDL attribute must reflect the element's commandfor content attribute.

The command getter steps are:

  1. Let command be this's command attribute.

  2. If command is in the Custom state, then return command's value.

  3. If command is in the Unknown state, then return the empty string.

  4. Return the keword corresponding to the value of command.

The command setter steps are to set the command content attribute to the given value.

The value attribute gives the element's value for the purposes of form submission. The element's value is the value of the element's value attribute, if there is one, or the empty string otherwise.

A button (and its value) is only included in the form submission if the button itself was used to initiate the form submission.


The following button is labeled "Show hint" and pops up a dialog box when activated:

<button type=button
        onclick="alert('This 15-20 minute piece was composed by George Gershwin.')">
 Show hint
</button>

The following shows how buttons can use commandfor to show and hide an element with the popover attribute when activated:

<button type=button
        commandfor="the-popover"
        command="show-popover">
 Show menu
</button>
<div popover
     id="the-popover">
 <button commandfor="the-popover"
         command="hide-popover">
  Hide menu
 </button>
</div>
    

The following shows how buttons can use commandfor with a custom command keyword on an element, demonstrating how one could use custom commands for unspecified behavior:

<button type=button
        commandfor="the-image"
        command="--rotate-landscape">
 Rotate Left
</button>
<button type=button
        commandfor="the-image"
        command="--rotate-portrait">
 Rotate Right
</button>
<img id="the-image"
     src="photo.jpg">
<script>
  const image = document.getElementById("the-image");
  image.addEventListener("command", (event) => {
   if ( event.command == "--rotate-landscape" ) {
    event.target.style.rotate = "-90deg"
   } else if ( event.command == "--rotate-portrait" ) {
    event.target.style.rotate = "0deg"
   }
  });
</script>
    

4.10.7 The select element

HTML element represents a control that provides a menu of options.">Element/select

Support in all current engines.

Firefox1+Safari1+Chrome1+
Opera2+Edge79+
Edge (Legacy)12+Internet ExplorerYes
Firefox Android4+Safari iOS?Chrome Android?WebView Android37+Samsung Internet?Opera Android10.1+
Categories:
Flow content.
Phrasing content.
Interactive content.
Listed, labelable, submittable, resettable, and autocapitalize-and-autocorrect inheriting form-associated element.
Palpable content.
Contexts in which this element can be used:
Where phrasing content is expected.
Content model:
Zero or more option, optgroup, hr, and script-supporting elements.
Tag omission in text/html:
Neither tag is omissible.
Content attributes:
Global attributes
autocomplete — Hint for form autofill feature
disabled — Whether the form control is disabled
form — Associates the element with a form element
multiple — Whether to allow multiple values
name — Name of the element to use for form submission and in the form.elements API
required — Whether the control is required for form submission
size — Size of the control
Accessibility considerations:
If the element has a multiple attribute or a size attribute with a value > 1: for authors; for implementers.
Otherwise: for authors; for implementers.
DOM interface:
Uses HTMLSelectElement.

The select element represents a control for selecting amongst a set of options.

, the manner by which the user opts for multiple values depends on the form control.">Attributes/multiple

Support in all current engines.

Firefox1+Safari3+Chrome1+
Opera?Edge79+
Edge (Legacy)12+Internet ExplorerYes
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android?

The multiple attribute is a boolean attribute. If the attribute is present, then the select element represents a control for selecting zero or more options from the list of options. If the attribute is absent, then the select element represents a control for selecting a single option from the list of options.

and the height of the element.">Element/optgroup

Support in all current engines.

Firefox1+Safari4+Chrome1+
Opera?Edge79+
Edge (Legacy)12+Internet Explorer5.5+
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android?
Categories:
None.
Contexts in which this element can be used:
As a child of a select element.
Content model:
Zero or more option and script-supporting elements.
Tag omission in text/html:
An optgroup element's end tag can be omitted if the optgroup element is immediately followed by another optgroup element, if it is immediately followed by an hr element, or if there is no more content in the parent element.
Content attributes:
Global attributes
disabled — Whether the form control is disabled
label — User-visible label
Accessibility considerations:
For authors.
For implementers.
DOM interface:
Uses HTMLOptGroupElement.

The optgroup element represents a group of option elements with a common label.

The element's group of option elements consists of the option elements that are children of the optgroup element.

Attributes/disabled

Support in all current engines.

Firefox1+Safari4+Chrome1+
Opera?Edge79+
Edge (Legacy)12+Internet Explorer8+
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android?

The disabled attribute is a boolean attribute and can be used to disable a group of option elements together.

The label attribute must be specified. Its value gives the name of the group, for the purposes of the user interface.

There is no way to select an optgroup element. Only option elements can be selected. An optgroup element merely provides a label for a group of option elements.

The following snippet shows how a set of lessons from three courses could be offered in a select drop-down widget:

<form action="courseselector.dll" method="get">
 <p>Which course would you like to watch today?
 <p><label>Course:
  <select name="c">
   <optgroup label="8.01 Physics I: Classical Mechanics">
    <option value="8.01.1">Lecture 01: Powers of Ten
    <option value="8.01.2">Lecture 02: 1D Kinematics
    <option value="8.01.3">Lecture 03: Vectors
   <optgroup label="8.02 Electricity and Magnetism">
    <option value="8.02.1">Lecture 01: What holds our world together?
    <option value="8.02.2">Lecture 02: Electric Field
    <option value="8.02.3">Lecture 03: Electric Flux
   <optgroup label="8.03 Physics III: Vibrations and Waves">
    <option value="8.03.1">Lecture 01: Periodic Phenomenon
    <option value="8.03.2">Lecture 02: Beats
    <option value="8.03.3">Lecture 03: Forced Oscillations with Damping
  </select>
 </label>
 <p><input type=submit value="▶ Play">
</form>

4.10.10 The option element

HTML element is used to define an item contained in a