A button element is said to be a submit button if any of the following are true:
the type attribute is in the Auto state, both the command and commandfor content attributes are not present, and the
parent node is not a select element;
or
Otherwise, return the result of running target‘s corresponding is valid
command steps given command.
The intent is to avoid dispatching a command event on an element type that does not support
that command.
However, element state is not considered. If an element can support a particular command, the
event is dispatched, even if that element is in a state where it cannot execute that command.
This means, for example, that command events are dispatched for popover commands on all HTML elements, even if they do not have a popover attribute.
Let continue be the result of firing an
event named command at target, using
CommandEvent, with its command
attribute initialized to command, its source attribute initialized to element,
and its cancelable attribute initialized to
true.
DOM standard issue
#1328 tracks how to better standardize associated event data in a way which makes sense on
Events. Currently an event attribute initialized to a value cannot also have a getter, and so
an internal slot (or map of additional fields) is required to properly specify this.
Otherwise, if the result of running check popover validity given
target, true, false, and null is true, then run the
hide popover algorithm given target, true,
true, false, and element.
Otherwise, if command is in the Show Popover state:
Otherwise, if this standard defines command steps for
target‘s local name, then run the
corresponding command steps given target, element,
and command.
If command is in the Custom state, then return command‘s
value.
If command is in the Unknown state, then return the empty
string.
Return the keyword corresponding to the value of command.
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; otherwise the empty string.
The element’s optional value is the value of the
element’s value attribute, if there is one; otherwise
null.
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:
<buttontype=buttononclick="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:
<buttontype=buttoncommandfor="the-popover"command="show-popover">
Show menu
</button><divpopoverid="the-popover"><buttoncommandfor="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:
<buttontype=buttoncommandfor="the-image"command="--rotate-landscape">
Rotate Left
</button><buttontype=buttoncommandfor="the-image"command="--rotate-portrait">
Rotate Right
</button><imgid="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"}elseif( event.command =="--rotate-portrait"){
event.target.style.rotate ="0deg"}});</script>
The size attribute
gives the number of options to show to the user. The size
attribute, if specified, must have a value that is a valid non-negative integer
greater than zero.
The required
attribute is a boolean attribute. When specified, the user will be required to select
a value before submitting the form.
The form attribute is used to explicitly associate the
select 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 autocomplete attribute controls how the user agent provides
autofill behavior.
If a select element has a required
attribute specified, does not have a multiple attribute
specified, and has a display size of 1; and if the value of the first option element in the
select element’s list of options (if
any) is the empty string, and that option element’s parent node is the
select element (and not an optgroup element), then that
option is the select element’s placeholder label option.
In practice, the requirement stated in the paragraph above can only apply when a
select element does not have a size attribute
with a value greater than 1.
If the multiple attribute is absent and the
element’s display size is greater than 1, then the user
agent should also allow the user to request that the option whose selectedness is true, if any, be unselected. Upon this
request being conveyed to the user agent, and before the relevant user interaction event is queued (e.g. before the click event), the user agent must set the selectedness of that option element to
false, set its dirtiness to true, and then
send select update notifications.
If the select is being rendered as a drop-down box with base
appearance, then the user agent should allow the user to open the picker given a corresponding select
element select and a corresponding mousedown or
keydown event event:
If the select is being rendered with base appearance, then the user
agent should allow the user to focus another option given the new option
element to focus option and a keydown event
event:
Implementations commonly allow the user to focus the next or previous option via
the arrow-up and arrow-down keys, focus the first or last option via the Home or End keys, or
focus the first or last option in the viewport of the picker via the PageUp or PageDown keys.
Which particular keys of the keyboard cause these actions might differ across
implementations and platforms. The ARIA Authoring Practices Guide has good recommendations
for this behavior.
If the multiple attribute is present, and the
element is not disabled, then the user agent should
allow the user to toggle the selectedness of the option elements in
its list of options that are themselves not disabled. Upon such an element being toggled (either through a click, or through a menu command, or any other mechanism), and before the relevant user
interaction event is queued (e.g. before a related click event), the selectedness of the option element must
be changed (from true to false or false to true), the dirtiness of the element must be set to true, and the
user agent must send select update notifications.
The display size of a select element is the
result of applying the rules for parsing non-negative integers to the value of the
element’s size attribute, if it has one and parsing it is
successful. If applying those rules to the attribute’s value is not successful, or if the size attribute is absent, then the element’s display size is 4 if the element’s multiple content attribute is present, and 1 otherwise.
To get the list of options given a
select element select:
The before argument can be a number, in which case element is inserted
before the item with that number, or an element from the list of options, in which case element is
inserted before that element.
If before is omitted, null, or a number out of range, then element will
be added at the end of the list.
The type IDL
attribute, on getting, must return the string “select-one” if the multiple attribute is absent, and the string “select-multiple” if the multiple
attribute is present.
The length
IDL attribute must return the number of nodes represented by the options collection.
On setting, it must act like the attribute of the same name on the options collection.
The item(index) method must return the value returned
by the method of the same name on the options collection, when invoked with the same argument.
The namedItem(name) method must return the value
returned by the method of the same name on the
options collection, when invoked with the same
argument.
The remove()
method must act like its namesake method on that same options collection when it has arguments, and like its namesake
method on the ChildNode interface implemented by the HTMLSelectElement
ancestor interface Element when it has no arguments.
The selectedOptions IDL attribute must return an
HTMLCollection rooted at the select node, whose filter matches the
elements in the list of options that have their
selectedness set to true.
This can result in no element having a selectedness set to true even in the case of the
select element having no multiple
attribute and a display size of 1.
The value
getter steps are to return the value of the
first option element in this‘s list of options in tree order that has its
selectedness set to true, if any. If there isn’t
one, then return the empty string.
This can result in no element having a selectedness set to true even in the case of the
select element having no multiple
attribute and a display size of 1.
For historical reasons, the default value of the size IDL attribute does not return the actual size used, which, in
the absence of the size content attribute, is either 1 or 4
depending on the presence of the multiple
attribute.
The following example shows how a select element can be used to offer the user
with a set of options from which the user can select a single option. The default option is
preselected.
<p><labelfor="unittype">Select unit type:</label><selectid="unittype"name="unittype"><optionvalue="1"> Miner </option><optionvalue="2"> Puffer </option><optionvalue="3"selected> Snipey </option><optionvalue="4"> Max </option><optionvalue="5"> Firebot </option></select></p>
When there is no default option, a placeholder can be used instead:
<selectname="unittype"required><optionvalue=""> Select unit type </option><optionvalue="1"> Miner </option><optionvalue="2"> Puffer </option><optionvalue="3"> Snipey </option><optionvalue="4"> Max </option><optionvalue="5"> Firebot </option></select>
Here, the user is offered a set of options from which they can select any number. By default,
all five options are selected.
<p><labelfor="allowedunits">Select unit types to enable on this map:</label><selectid="allowedunits"name="allowedunits"multiple><optionvalue="1"selected> Miner </option><optionvalue="2"selected> Puffer </option><optionvalue="3"selected> Snipey </option><optionvalue="4"selected> Max </option><optionvalue="5"selected> Firebot </option></select></p>
Sometimes, a user has to select one or more items. This example shows such an interface.
<label>
Select the songs from that you would like on your Act II Mix Tape:
<selectmultiplerequiredname="act2"><optionvalue="s1">It Sucks to Be Me (Reprise)
<optionvalue="s2">There is Life Outside Your Apartment
<optionvalue="s3">The More You Ruv Someone
<optionvalue="s4">Schadenfreude
<optionvalue="s5">I Wish I Could Go Back to College
<optionvalue="s6">The Money Song
<optionvalue="s7">School for Monsters
<optionvalue="s8">The Money Song (Reprise)
<optionvalue="s9">There's a Fine, Fine Line (Reprise)
<optionvalue="s10">What Do You Do With a B.A. in English? (Reprise)
<optionvalue="s11">For Now
</select></label>
Occasionally it can be useful to have a separator:
<label>
Select the song to play next:
<selectrequiredname="next"><optionvalue="sr">Random
<hr><optionvalue="s1">It Sucks to Be Me (Reprise)
<optionvalue="s2">There is Life Outside Your Apartment
…
<select><button><selectedcontent></selectedcontent></button><divclass="border"><optgroup><legend>WHATWG Specifications</legend><option><imgsrc="html.jpg"alt="">
HTML
</option><option><imgsrc="dom.jpg"alt="">
DOM
</option></optgroup></div><divclass="border"><optgroup><legend>W3C Specifications</legend><option><imgsrc="forms.jpg"alt="">
CSS Form Control Styling
</option><option><imgsrc="pseudo.jpg"alt="">
CSS Pseudo-Elements
</option><optgroup></div></select>
The first child button
element as allowed by the content model of select is not a submit button. It is used
to replace the in-page rendering of the select element. Its form submission behavior
is prevented because it is inert.
The datalist element represents a set of option elements that
represent predefined options for other controls. In the rendering, the datalist
element represents nothing and it, along with its children, should
be hidden.
The datalist element can be used in two ways. In the simplest case, the
datalist element has just option element children.
In the more elaborate case, the datalist element can be given contents that are to
be displayed for down-level clients that don’t support datalist. In this case, the
option elements are provided inside a select element inside the
datalist element.
<label>
Animal:
<inputname=animallist=animals></label><datalistid=animals><label>
or select from the list:
<selectname=animal><optionvalue=""><option>Cat
<option>Dog
</select></label></datalist>
The datalist element is hooked up to an input element using the list attribute on the input element.
Each option element that is a descendant of the datalist element,
that is not disabled, and whose value is a string that isn’t the empty string, represents a
suggestion. Each suggestion has a value and a label.
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.
The element’s group of option elements
consists of the option elements that are descendants of the optgroup
element.
When showing option elements in select elements, user agents should
show the option elements of such groups as being related to each other and separate
from other option elements.
Otherwise, return the value of optgroup‘s label attribute.
The value of the optgroup label
algorithm gives the name of the group, for the purposes of the user interface. User agents should use this attribute’s value when labeling the group of
option elements in a select element.
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:
<formaction="courseselector.dll"method="get"><p>Which course would you like to watch today?
<p><label>Course:
<selectname="c"><optgrouplabel="8.01 Physics I: Classical Mechanics"><optionvalue="8.01.1">Lecture 01: Powers of Ten
<optionvalue="8.01.2">Lecture 02: 1D Kinematics
<optionvalue="8.01.3">Lecture 03: Vectors
<optgrouplabel="8.02 Electricity and Magnetism"><optionvalue="8.02.1">Lecture 01: What holds our world together?
<optionvalue="8.02.2">Lecture 02: Electric Field
<optionvalue="8.02.3">Lecture 03: Electric Flux
<optgrouplabel="8.03 Physics III: Vibrations and Waves"><optionvalue="8.03.1">Lecture 01: Periodic Phenomenon
<optionvalue="8.03.2">Lecture 02: Beats
<optionvalue="8.03.3">Lecture 03: Forced Oscillations with Damping
</select></label><p><inputtype=submitvalue="▶ Play"></form>
An option element’s end tag can be omitted if
the option element is immediately followed by another option element, if
it is immediately followed by an optgroup element, if it is immediately followed by
an hr element, or if there is no more content in the parent element.
Being disabled does not prevent all
modifications to the option element. For example, its selectedness could be modified programmatically from
JavaScript. Or, it could be indirectly modified by user action, e.g., if other non-disabled
option elements in the select element were modified.
The label
attribute provides a label for element. The label of an
option element is the value of the label
content attribute, if there is one and its value is not the empty string, or, otherwise, the value
of the element’s text IDL attribute.
The label content attribute, if specified, must not be
empty.
The value
attribute provides a value for element. The value of an
option element is the value of the value
content attribute, if there is one, or, if there is not, the result of collect option
text given this and false.
The dirtiness of an option element is
a boolean state, initially false. It controls whether adding or removing the selected content attribute has any effect.
The selectedness of an option
element is a boolean state, initially false. Except where otherwise specified, when the element is
created, its selectedness must be set to true if
the element has a selected attribute. Whenever an
option element’s selected attribute is
added, if its dirtiness is false, its selectedness must be set to true. Whenever an
option element’s selected attribute is
removed, if its dirtiness is false, its
selectedness must be set to false.
The Option() constructor, when called with three
or fewer arguments, overrides the initial state of the selectedness state to always be false even if the third
argument is true (implying that a selected attribute is
to be set). The fourth argument can be used to explicitly set the initial selectedness state when using the constructor.
A select element whose multiple
attribute is not specified must not have more than one descendant option element with
its selected attribute set.
The defaultSelected argument sets the selected attribute.
The selected argument sets whether or not the element is selected. If it is
omitted, even if the defaultSelected argument is true, the element is not
selected.
The value
getter steps are to return this‘s value.
The selected IDL attribute, on getting, must return true if
the element’s selectedness is true, and false
otherwise. On setting, it must set the element’s selectedness to the new value, set its dirtiness to true, and then cause the element to
ask for a reset.
The index
IDL attribute must return the element’s index.
A legacy factory function is provided for creating HTMLOptionElement objects (in
addition to the factory methods from DOM such as createElement()): Option(text, value,
defaultSelected, selected). When invoked, the legacy factory
function must perform the following steps:
If descendant is a Text node, then set text to the
concatenation of text and descendant‘s data.
If descendant is an img element and includeAltText is
true, then:
If the value of descendant‘s alt
attribute is not empty, then set text to the concatenation of text,
" ", the value of descendant‘s alt attribute, and " ".
When no value
attribute is set on the option element, its text contents are used to generate a
submittable value. In the case that the option element has child elements, this can
lead to unexpected results such as option elements which render differently but have
the same value. In order to address this, setting the value attribute on option elements is
recommended.
The textarea element represents a multiline plain text edit
control for the element’s raw
value. The contents of the control represent the control’s default value.
The raw value of a textarea
control must be initially the empty string.
The readonly attribute is a boolean
attribute used to control whether the text can be edited by the user or not.
In this example, a text control is marked read-only because it represents a read-only
file:
Filename: <code>/etc/bash.bashrc</code><textareaname="buffer"readonly>
# System-wide .bashrc file for interactive bash(1) shells.
# To enable the settings / commands in this file for login shells as well,
# this file has to be sourced in /etc/profile.
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
...</textarea>
When a textarea is mutable, its raw value should be editable by the user: the user
agent should allow the user to edit, insert, and remove text, and to insert and remove line breaks
in the form of U+000A LINE FEED (LF) characters. Any time the user causes the element’s raw value to change, the user agent must queue an
element task on the user interaction task source given the
textarea element to fire an event named
input at the textarea element, with the bubbles and composed
attributes initialized to true. User agents may wait for a suitable break in the user’s
interaction before queuing the task; for example, a user agent could wait for the user to have not
hit a key for 100ms, so as to only fire the event when the user pauses, instead of continuously
for each keystroke.
A textarea element’s dirty value flag must
be set to true whenever the user interacts with the control in a way that changes the raw value.
If the element is mutable, the user agent should allow
the user to change the writing direction of the element, setting it either to a left-to-right
writing direction or a right-to-left writing direction. If the user does so, the user agent must
then run the following steps:
Set the element’s dir attribute to “ltr” if the user selected a left-to-right writing direction, and
“rtl” if the user selected a right-to-left writing
direction.
The cols
attribute specifies the expected maximum number of characters per line. If the cols attribute is specified, its value must be a valid
non-negative integer greater than zero. If applying the rules for
parsing non-negative integers to the attribute’s value results in a number greater than
zero, then the element’s character width is that
value; otherwise, it is 20.
The user agent may use the textarea element’s character width as a hint to the user as to how many
characters the server prefers per line (e.g. for visual user agents by making the width of the
control be that many characters). In visual renderings, the user agent should wrap the user’s
input in the rendering so that each line is no wider than this number of characters.
The rows
attribute specifies the number of lines to show. If the rows attribute is specified, its value must be a valid
non-negative integer greater than zero. If applying the rules for
parsing non-negative integers to the attribute’s value results in a number greater than
zero, then the element’s character height is that
value; otherwise, it is 2.
Visual user agents should set the height of the control to the number of lines given by character height.
The wrap
attribute is an enumerated attribute with the following keywords and states:
Keyword
State
Brief description
soft
Soft
Text is not to be wrapped when submitted (though can still be wrapped in the rendering).
hard
Hard
Text is to have newlines added by the user agent so that the text is wrapped when it is
submitted.
If the element’s wrap attribute is in the Hard state, the cols attribute must be specified.
For historical reasons, the element’s value is normalized in three different ways for three
different purposes. The raw value is the value as
it was originally set. It is not normalized. The API
value is the value used in the value IDL
attribute, textLength IDL attribute, and by the
maxlength and minlength content attributes. It is normalized so that line
breaks use U+000A LINE FEED (LF) characters. Finally, there is the value, as used in form submission and other processing models in
this specification. It is normalized as for the API
value, and in addition, if necessary given the element’s wrap attribute, additional line breaks are inserted to wrap the
text at the given width.
The element’s value is defined to be the element’s API value with the textarea wrapping
transformation applied. The textarea wrapping transformation is the following
algorithm, as applied to a string:
If the element’s wrap attribute is in the Hard state, insert U+000A LINE FEED (LF) characters
into the string using an implementation-defined algorithm so that each line has no
more than character width characters. For the
purposes of this requirement, lines are delimited by the start of the string, the end of the
string, and U+000A LINE FEED (LF) characters.
The required attribute is a boolean
attribute. When specified, the user will be required to enter a value before submitting the
form.
Constraint validation: If the element has its required attribute specified, and the element is mutable, and the element’s value is the empty string, then the element is suffering
from being missing.
The placeholder attribute represents a short
hint (a word or short phrase) intended to aid the user with data entry when the control has no
value. A hint could be a sample value or a brief description of the expected format.
The placeholder attribute should not be used as
an alternative to a label. For a longer hint or other advisory text, the title attribute is more appropriate.
These mechanisms are very similar but subtly different: the hint given by the
control’s label is shown at all times; the short hint given in the placeholder attribute is shown before the user enters a
value; and the hint in the title attribute is shown when the user
requests further help.
User agents should present this hint to the user when the element’s value is the empty string and the control is not
focused (e.g. by displaying it inside a blank unfocused control). All U+000D CARRIAGE
RETURN U+000A LINE FEED character pairs (CRLF) in the hint, as well as all other U+000D CARRIAGE
RETURN (CR) and U+000A LINE FEED (LF) characters in the hint, must be treated as line breaks when
rendering the hint.
If a user agent normally doesn’t show this hint to the user when the control is
focused, then the user agent should nonetheless show the hint for the control if it
was focused as a result of the autofocus attribute, since
in that case the user will not have had an opportunity to examine the control before focusing
it.
The name attribute represents the element’s name.
The dirname attribute controls how the element’s directionality is submitted.
The disabled attribute is used to make the control
non-interactive and to prevent its value from being submitted.
The form attribute is used to explicitly associate the
textarea element with its form owner.
The autocomplete attribute controls how the user agent
provides autofill behavior.
Here is an example of a textarea being used for unrestricted free-form text input
in a form:
<p>If you have any comments, please let us know: <textareacols=80name=comments></textarea></p>
To specify a maximum length for the comments, one can use the maxlength attribute:
<p>If you have any short comments, please let us know: <textareacols=80name=commentsmaxlength=200></textarea></p>
To give a default value, text can be included inside the element:
<p>If you have any comments, please let us know: <textareacols=80name=comments>You rock!</textarea></p>
You can also give a minimum length. Here, a letter needs to be filled out by the user; a
template (which is shorter than the minimum length) is provided, but is insufficient to submit
the form:
<textarearequiredminlength="500">Dear Madam Speaker,
Regarding your letter dated ...
...
Yours Sincerely,
...</textarea>
A placeholder can be given as well, to suggest the basic form to the user, without providing
an explicit template:
<textareaplaceholder="Dear Francine,They closed the parks this week, so we won't be able tomeet your there. Should we just have dinner?Love,Daddy"></textarea>
To have the browser submit the directionality of the element along with the
value, the dirname attribute can be specified:
<p>If you have any comments, please let us know (you may use either English or Hebrew for your comments):
<textareacols=80name=commentsdirname=comments.dir></textarea></p>
The for content
attribute allows an explicit relationship to be made between the result of a calculation and the
elements that represent the values that went into the calculation or that otherwise influenced the
calculation. The for attribute, if specified, must contain a
string consisting of an unordered set of unique space-separated tokens, none of which
are identical to another token and each of which must have the value of an ID of an element in the same tree.
The form attribute is used to explicitly associate the
output element with its form owner. The name attribute represents the element’s name. The output
element is associated with a form so that it can be easily referenced from the event
handlers of form controls; the element’s value itself is not submitted when the form is
submitted.
The element has a default value
override (null or a string). Initially it must be null.
The element’s default value is determined by
the following steps:
The progress element represents the completion progress of a task.
The progress is either indeterminate, indicating that progress is being made but that it is not
clear how much more work remains to be done before the task is complete (e.g. because the task is
waiting for a remote host to respond), or the progress is a number in the range zero to a maximum,
giving the fraction of work that has so far been completed.
There are two attributes that determine the current task completion represented by the element.
The value
attribute specifies how much of the task has been completed, and the max attribute specifies how much work
the task requires in total. The units are arbitrary and not specified.
To make a determinate progress bar, add a value attribute with the current progress (either a number from
0.0 to 1.0, or, if the max attribute is specified, a number
from 0 to the value of the max attribute). To make an
indeterminate progress bar, remove the value
attribute.
Authors are encouraged to also include the current value and the maximum value inline as text
inside the element, so that the progress is made available to users of legacy user agents.
Here is a snippet of a web application that shows the progress of some automated task:
(The updateProgress() method in this example would be called by some
other code on the page to update the actual progress bar as the task progressed.)
The value and max attributes, when present, must have values that are valid floating-point numbers. The value attribute, if present, must have a value greater than or
equal to zero, and less than or equal to the value of the max attribute, if present, or 1.0, otherwise. The max attribute, if present, must have a value greater than
zero.
The progress element is the wrong element to use for something that
is just a gauge, as opposed to task progress. For instance, indicating disk space usage using
progress would be inappropriate. Instead, the meter element is available
for such use cases.
User agent requirements: If the value
attribute is omitted, then the progress bar is an indeterminate progress bar. Otherwise, it is a
determinate progress bar.
If the progress bar is a determinate progress bar and the element has a max attribute, the user agent must parse the max attribute’s value according to the rules for parsing
floating-point number values. If this does not result in an error, and if the parsed value
is greater than zero, then the maximum value of the
progress bar is that value. Otherwise, if the element has no max attribute, or if it has one but parsing it resulted in an
error, or if the parsed value was less than or equal to zero, then the maximum value of the progress bar is 1.0.
If the progress bar is a determinate progress bar, user agents must parse the value attribute’s value according to the rules for
parsing floating-point number values. If this does not result in an error and the parsed
value is greater than zero, then the value of the
progress bar is that parsed value. Otherwise, if parsing the value attribute’s value resulted in an error or a number less
than or equal to zero, then the value of the progress
bar is zero.
If the progress bar is a determinate progress bar, then the current value is the maximum value, if value is greater than the maximum value, and value otherwise.
UA requirements for showing the progress bar: When representing a
progress element to the user, the UA should indicate whether it is a determinate or
indeterminate progress bar, and in the former case, should indicate the relative position of the
current value relative to the maximum value.
For a determinate progress bar (one with known current and maximum values), returns the
result of dividing the current value by the maximum value.
For an indeterminate progress bar, returns −1.
If the progress bar is an indeterminate progress bar, then the position IDL attribute
must return −1. Otherwise, it must return the result of dividing the current value by the maximum value.
The value getter steps are to return 0 if this
is an indeterminate progress bar; otherwise this‘s current value.
Setting the value IDL attribute to itself
when the corresponding content attribute is absent would change the progress bar from an
indeterminate progress bar to a determinate progress bar with no progress.
The labels IDL attribute provides a list of the element’s
labels.
The meter element represents a scalar measurement within a known
range, or a fractional value; for example disk usage, the relevance of a query result, or the
fraction of a voting population to have selected a particular candidate.
This is also known as a gauge.
The meter element should not be used to indicate progress (as in a progress bar).
For that role, HTML provides a separate progress element.
The meter element also does not represent a scalar value of arbitrary
range — for example, it would be wrong to use this to report a weight, or height, unless
there is a known maximum value.
There are six attributes that determine the semantics of the gauge represented by the
element.
The min attribute
specifies the lower bound of the range, and the max attribute specifies the upper bound. The value attribute specifies
the value to have the gauge indicate as the “measured” value.
The other three attributes can be used to segment the gauge’s range into “low”, “medium”, and
“high” parts, and to indicate which part of the gauge is the “optimum” part. The low attribute specifies the range that is
considered to be the “low” part, and the high attribute specifies the range that is considered to be
the “high” part. The optimum attribute gives the position that is “optimum”;
if that is higher than the “high” value then this indicates that the higher the value, the better;
if it’s lower than the “low” mark then it indicates that lower values are better, and naturally if
it is in between then it indicates that neither high nor low values are good.
If no minimum or maximum is specified, then the range is assumed to be 0..1, and
the value thus has to be within that range.
Authors are encouraged to include a textual representation of the gauge’s state in the
element’s contents, for users of user agents that do not support the meter
element.
When used with microdata, the meter element’s value attribute provides the element’s machine-readable value.
The following examples show three gauges that would all be three-quarters full:
Storage space usage: <metervalue=6max=8>6 blocks used (out of 8 total)</meter>
The following example is incorrect use of the element, because it doesn’t give a range (and
since the default maximum is 1, both of the gauges would end up looking maxed out):
<p>The grapefruit pie had a radius of <metervalue=12>12cm</meter>
and a height of <metervalue=2>2cm</meter>.</p><!-- BAD! -->
Instead, one would either not include the meter element, or use the meter element with a
defined range to give the dimensions in context compared to other pies:
<p>The grapefruit pie had a radius of 12cm and a height of
2cm.</p><dl><dt>Radius: <dd><metermin=0max=20value=12>12cm</meter><dt>Height: <dd><metermin=0max=10value=2>2cm</meter></dl>
There is no explicit way to specify units in the meter element, but the units may
be specified in the title attribute in free-form text.
The example above could be extended to mention the units:
User agents must then use all these numbers to obtain values for six points on the gauge, as
follows. (The order in which these are evaluated is important, as some of the values refer to
earlier ones.)
The minimum value
If the min attribute is specified and a value could be
parsed out of it, then the minimum value is that value. Otherwise, the minimum value is
zero.
The maximum value
If the max attribute is specified and a value could be
parsed out of it, then the candidate maximum value is that value. Otherwise, the candidate
maximum value is 1.0.
If the candidate maximum value is greater than or equal to the minimum value, then the
maximum value is the candidate maximum value. Otherwise, the maximum value is the same as the
minimum value.
The actual value
If the value attribute is specified and a value could
be parsed out of it, then that value is the candidate actual value. Otherwise, the candidate
actual value is zero.
If the candidate actual value is less than the minimum value, then the actual value is the
minimum value.
Otherwise, if the candidate actual value is greater than the maximum value, then the actual
value is the maximum value.
Otherwise, the actual value is the candidate actual value.
The low boundary
If the low attribute is specified and a value could be
parsed out of it, then the candidate low boundary is that value. Otherwise, the candidate low
boundary is the same as the minimum value.
If the candidate low boundary is less than the minimum value, then the low boundary is the
minimum value.
Otherwise, if the candidate low boundary is greater than the maximum value, then the low
boundary is the maximum value.
Otherwise, the low boundary is the candidate low boundary.
The high boundary
If the high attribute is specified and a value could be
parsed out of it, then the candidate high boundary is that value. Otherwise, the candidate high
boundary is the same as the maximum value.
If the candidate high boundary is less than the low boundary, then the high boundary is the
low boundary.
Otherwise, if the candidate high boundary is greater than the maximum value, then the high
boundary is the maximum value.
Otherwise, the high boundary is the candidate high boundary.
The optimum point
If the optimum attribute is specified and a value
could be parsed out of it, then the candidate optimum point is that value. Otherwise, the
candidate optimum point is the midpoint between the minimum value and the maximum value.
If the candidate optimum point is less than the minimum value, then the optimum point is the
minimum value.
Otherwise, if the candidate optimum point is greater than the maximum value, then the optimum
point is the maximum value.
Otherwise, the optimum point is the candidate optimum point.
All of which will result in the following inequalities all being true:
minimum value ≤ actual value ≤ maximum value
minimum value ≤ low boundary ≤ high boundary ≤ maximum value
minimum value ≤ optimum point ≤ maximum value
UA requirements for regions of the gauge: If the optimum point is equal to the
low boundary or the high boundary, or anywhere in between them, then the region between the low
and high boundaries of the gauge must be treated as the optimum region, and the low and high
parts, if any, must be treated as suboptimal. Otherwise, if the optimum point is less than the low
boundary, then the region between the minimum value and the low boundary must be treated as the
optimum region, the region from the low boundary up to the high boundary must be treated as a
suboptimal region, and the remaining region must be treated as an even less good region. Finally,
if the optimum point is higher than the high boundary, then the situation is reversed; the region
between the high boundary and the maximum value must be treated as the optimum region, the region
from the high boundary down to the low boundary must be treated as a suboptimal region, and the
remaining region must be treated as an even less good region.
UA requirements for showing the gauge: When representing a meter
element to the user, the UA should indicate the relative position of the actual value to the
minimum and maximum values, and the relationship between the actual value and the three regions of
the gauge.
The fieldset element represents a set of form controls (or other
content) grouped together, optionally with a caption. The caption is given by the first
legend element that is a child of the fieldset element, if any. The
remainder of the descendants form the group.
The disabled attribute, when specified, causes all the
form control descendants of the fieldset element, excluding those that are
descendants of the fieldset element’s first legend element child, if
any, to be disabled.
A fieldset element is a disabled
fieldset if it matches any of the following conditions:
It is a descendant of another fieldset element whose disabled attribute is specified, and is not a
descendant of that fieldset element’s first legend element child, if
any.
The form attribute is used to explicitly associate the
fieldset element with its form owner. The name attribute represents the element’s name.
This example shows a fieldset element being used to group a set of related
controls:
<fieldset><legend>Display</legend><p><label><inputtype=radioname=cvalue=0checked> Black on White</label><p><label><inputtype=radioname=cvalue=1> White on Black</label><p><label><inputtype=checkboxname=g> Use grayscale</label><p><label>Enhance contrast <inputtype=rangename=elist=contrastmin=0max=100value=0step=1></label><datalistid=contrast><optionlabel=Normalvalue=0><optionlabel=Maximumvalue=100></datalist></fieldset>
The following snippet shows a fieldset with a checkbox in the legend that controls whether or
not the fieldset is enabled. The contents of the fieldset consist of two required text controls
and an optional year/month control.
<fieldsetname="clubfields"disabled><legend><label><inputtype=checkboxname=clubonchange="form.clubfields.disabled = !checked">
Use Club Card
</label></legend><p><label>Name on card: <inputname=clubnamerequired></label></p><p><label>Card number: <inputname=clubnumrequiredpattern="[-0-9]+"></label></p><p><label>Expiry date: <inputname=clubexptype=month></label></p></fieldset>
You can also nest fieldset elements. Here is an example expanding on the previous
one that does so:
<fieldsetname="clubfields"disabled><legend><label><inputtype=checkboxname=clubonchange="form.clubfields.disabled = !checked">
Use Club Card
</label></legend><p><label>Name on card: <inputname=clubnamerequired></label></p><fieldsetname="numfields"><legend><label><inputtype=radiocheckedname=clubtypeonchange="form.numfields.disabled = !checked">
My card has numbers on it
</label></legend><p><label>Card number: <inputname=clubnumrequiredpattern="[-0-9]+"></label></p></fieldset><fieldsetname="letfields"disabled><legend><label><inputtype=radioname=clubtypeonchange="form.letfields.disabled = !checked">
My card has letters on it
</label></legend><p><label>Card code: <inputname=clubletrequiredpattern="[A-Za-z]+"></label></p></fieldset></fieldset>
In this example, if the outer “Use Club Card” checkbox is not checked, everything inside the
outer fieldset, including the two radio buttons in the legends of the two nested
fieldsets, will be disabled. However, if the checkbox is checked, then the radio
buttons will both be enabled and will let you select which of the two inner
fieldsets is to be enabled.
This example shows a grouping of controls where the legend element both labels
the grouping, and the nested heading element surfaces the grouping in the document outline:
<fieldset><legend><h2>
How can we best reach you?
</h2></legend><p><label><inputtype=radiocheckedname=contact_pref>
Phone
</label></p><p><label><inputtype=radioname=contact_pref>
Text
</label></p><p><label><inputtype=radioname=contact_pref>
Email
</label></p></fieldset>
Returns the element’s form element, if any, or null otherwise.
The form IDL
attribute’s behavior depends on whether the legend element is in a
fieldset element or not. If the legend has a fieldset
element as its parent, then the form IDL attribute must
return the same value as the form IDL attribute on that
fieldset element. Otherwise, it must return null.
The selectedcontent element reflects the contents of a select
element’s currently selected option element. selectedcontent elements
can be used to declaratively show the selected option element’s contents within the
select element’s first child button element.
The option element’s label
attribute can be used to render a visible label for the option, but the
selectedcontent element will not reflect the content of the label attribute.
Every selectedcontent element has a disabled state, which is a boolean, initially set to
false.
To update a select‘s selectedcontent given a
select element select: