value

The value attribute in HTML sets the default value for form elements, determining what is shown or sent when the page initially loads.

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

index.html
<tagname value="text" />

Example

<button>

Two <button> with equal names, that submit different values when clicked:

The button value attribute
Choose your favorite subject:
index.html
<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:

The li value attribute
  1. Coffee
  2. Tea
  3. Milk
  4. Water
  5. Juice
  6. Beer
index.html
<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:

ElementsAttribute
<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.