The
value attribute in HTML is used to specify the value of the element with which it is used. It has different meaning for different HTML elements.
Usage: It can be used with the following elements: <input>, <button>, <meter>, <li>, <option>, <progress>, and <param>, <output>.
<input>: When the value attribute is present, it specifies the initial value of the input element.
It has a different meaning for different input type:
- When present in "button", "reset" and "submit" it specifies the text on the button.
- When present in "text", "password" and "hidden" it specifies the initial value of the input field.
- When present in "checkbox", "radio" and "image" it specifies the value associated with the input.
- Syntax:
<input value = "value">
- Example-1:
- Output:
👁 valueinput
- Example-2:
- Output:
👁 inputvalue
<button>: When the value attribute is present, it specifies the initial value of the button element.
- Syntax:
<button value = "value">
- Example:
- Output:
Before clicking the button:
👁 valuebutton
After clicking the button:
👁 valuebutton
<meter>: It specifies the current value of the gauge. The value must be between min and max attribute.
- Syntax:
<meter value = "value">
- Example:
- Output:
👁 valuemeter
<li>: When the value attribute is present, it specifies the initial value of the list item. It is only applicable on the ordered list.
- Syntax:
<li value = "number">list item </li>
- number: specifies the value of the list item.
- Example:
- Output:
👁 valuelist
<option>: When the value attribute is present, it specifies the value of the option element.
- Syntax:
<option value = "value"></option>
- Example:
- Output:
Before clicking the button:
👁 valueoption
After clicking the button:
👁 valueoption
<progress>: When the value attribute is present, it specifies the value of the progress element.
- Syntax:
<progress value = "number"></progress>
- number specifies the initial value of the progress element.
- Example:
- Output:
👁 valueprogress
Supported Browsers: The browser supported by value attribute in progress element are listed below:
- Google Chrome
- Internet Explorer
- Firefox
- Opera
- Safari