HTML <input> value Attribute
Example
<form action="action.php">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname" value="John"><br><br>
<label for="lname">Last name:</label>
<input type="text" id="lname" name="lname" value="Doe"><br><br>
<input type="submit" value="Submit">
</form>
Meaning
The value attribute has two different uses, depending on the value for the type attribute.
With data-entry controls <input type="text"> and <input type="password">, this attribute is used to set the default value for the control.
When used with checkbox or radio button form controls, this attribute specifies the return value for the control. If it is not set for these fields, a default value of on will be submitted when the control is activated.
When specified in the HTML, this is the initial value, and from then on it can be altered or retrieved at any time using JavaScript to access the respective HTMLInputElement object's value property.
The value attribute is always optional, though should be considered mandatory for checkbox, radio, and hidden.
Standard Syntax
HTML: <input value="text">
XHTML: <input value="text"/>
Attribute Values
| Value | Description |
|---|---|
| text | Specifies the value of the <input> element. |