The value attribute
The value
attribute specifies a default value for the HTML form input field. It will be automatically inserted into it when the page is visited.
Applies to tags input
, option
and others.
Text input
In the case of a text input field input
the contents of the value
attribute will set the default text visible in the field (you can delete it and write your own).
Button
If the attribute is applied to a button created via the input
tag with the type
attribute in the values button
, submit
or reset
, the value
attribute will set the text for the button.
Checkbox
If the attribute is applied to a checkbox, no external changes will be observed, but the checked checkbox will send the content of this attribute to the server. If the checkbox does not have the value
attribute, it will send the string 'on'
. If the checkbox is unchecked, nothing will be sent to the server regardless of the presence of the value
attribute.
Radio switch
For a group of radio switches, you need to set different values for the value
attribute so that after sending to the server, a server-side language such as PHP or NodeJS can determine which switch was selected.
option tag
If the tag option
does not have the attribute value
, then the content of the tag option
will be sent to the server. If the attribute is set, its content will be sent.
Example
Let's set the default text for the input field:
<input type="text" value="default text">
:
Example
Now let's change the button text:
<input type="submit" value="click me">
:
See also
-
attribute
placeholder
,
which sets the hint in the input field