value
value attribute
The value
attribute in HTML defines the default or initial value for elements such as <input>
, <button>
, <option>
, <meter>
, and <progress>
. It specifies the value that is shown or submitted when the form is first loaded or reset.
Syntax
<tagname value="text" />
Example
<button>
Two <button>
with equal names, that submit different values when clicked:
<h1>The button value attribute</h1>
<form>
<h2>Choose your favorite subject: </h2>
<button name="subject" type="submit" value="fav_HTML">HTML</button>
<button name="subject" type="submit" value="fav_CSS">CSS</button>
</form>
<li>
Use of the value attribute in an ol
:
- Coffee
- Tea
- Milk
- Water
- Juice
- Beer
<h1>The li value attribute</h1>
<ol>
<li value="100">Coffee</li>
<li>Tea</li>
<li>Milk</li>
<li>Water</li>
<li>Juice</li>
<li>Beer</li>
</ol>
Applicable to
The value
attribute can be applied to the following elements:
Elements | Attribute |
---|---|
<button> | value |
<input> | value |
<meter> | value |
<li> | value |
<option> | value |
<progress> | value |
<param> | value |
Values
- text
- A string consisting of letters and numbers.
Conclusion
The value
attribute in HTML is used to set the default value for form elements like <input>
, <button>
, and <option>
. It determines what is displayed or submitted when the form is first loaded or reset. This attribute enhances form interactivity by defining preset values.
type
The type attribute in HTML determines the kind of input or form control, defining its purpose and the type of data it can handle, such as text, number, or date.
Specific
Specific attributes in HTML control element behavior, improving interactivity and usability. They include Form, Input, and Media attributes, each serving a unique role.