What is the value attribute in HTML?
Overview
In HTML, the value attribute is applied to the input element. Its uses are as follows:
- To provide a default value to the input element.
- To change the value of the input element dynamically, using Javascript.
Syntax
<input value="text">
Parameters
This attribute takes text as an argument. It represents the default value for the input element.
Example
<html><head></head><body><div id="content"><label for="city">City:</label><!-- provide value attribute --><input id="city" type="text" value="Paris"></div></body></html>
Explanation
In the example above, we take city as the input from the user and assign its default value as Paris. If the user doesn’t provide a value for city while submitting the form, the default value is submitted.