Live Demo
Firefox | Safari | Safari | Chrome | Opera | IE | Android |
---|---|---|---|---|---|---|
The Low Down
The value
attribute is used to set the value of <input>
elements: it defines the value associated with the input and the value in the name/value pair that is sent to the server on form submission.
- The
value
attribute is valid for<button>
,<option>
,<input>
, as well as<li>
,<meter>
,<progress>
,<param>
- The value attribute behaves slightly differently depending on the input type.
- For select options, the value of the selected
<option>
gets submitted with the form. If the value of an<option>
is not explicitly defined, its default value is the text content of the element. If no label attribute is set and the option textnode is null, the value of thevalue
attribute, if present, gets displayed as a label explaining the option. - In terms of
<button>
, thevalue
attribute defines the value part of the name/value pair associated with this button for the purposes of form submission. - If the user may change directionality, consider including the
dirname
attribute. - In terms of
<progress>
, its value must be a valid floating point number between 0 and max, or between 0 and 1 if max is omitted, showing what percent of the task is complete. If there is novalue
attribute, the progress bar is indeterminate. - In terms of
<meter>
, it represents the current numeric value, and is what the meter will display. Required, the value must be between themin
andmax
values inclusive. If it falls outside the min/max range, the value will equal either the min or max if its under or over range respectively. - Not relevant to forms, but the
value
attribute on<li>
within an<ol>
defines the number marker, or ordinal number of that list item. The adjacent<li>
s will increment normally starting with that value. - Also not relevant to forms, but the
value
attribute is a required attribute of<param>
, setting the value of the parameter.