In this section, we will learn what the value attribute is and how to use it.
What is value Attribute in HTML <input> Tag?
The value attribute is used to set a default value for an <input> element.
This value is considered as the default and if users don’t set any value for the target <input> field, this value will be sent to a server instead.
For example, let’s say you have an <input> element of type “text”. Now, if in the target textbox you don’t provide a value, then the default value set in the `value` attribute is the one to be sent to a server when submitting the form data.
Also, for HTML elements like `checkbox` and `radio box` the only way to set a value for them is by using the `value` attribute. So for these types of elements that can’t take values from users directly, this is the only method of setting values for them.
HTML value Attribute in <input> Tag Syntax:
<input type = “type” value = “default-value”>
Example: using value attribute in HTML <input> tag
See the Pen using value attribute in HTML <input> tag by Omid Dehghan (@odehghan) on CodePen.