HTML value Attribute
Description
The HTML value
attribute is used to define the initial or default value of an input element such as <input>
, <button>
, <option>
, <meter>
, or <progress>
. It specifies the value that will be displayed or submitted when the form is initially loaded or reset.
For example, in an <input>
element of type "text" or "number", the value
attribute defines the initial text displayed in the input field. Similarly, in a <button>
element, it sets the initial label displayed on the button. In <option>
elements within a <select>
element, the value
attribute specifies the value that will be submitted if that option is selected.
Here's a basic example of its usage:
<input type="text" value="Default Text">
In this example, the initial value of the text input field will be "Default Text".
It's important to note that while the value
attribute sets the initial value, users can still change this value interactively in the browser. If you want to prevent user modification, you might consider using the readonly
attribute in conjunction with value
, or setting the disabled
attribute if user input should be entirely disabled.
Syntax
<tagname value="text">
Values
- textAn alphanumeric string.
Applies To
The value
attribute can be used on the following html elements.
Example
<form action="formscript.php" method="post">
<label for="name">Name:</label><br>
<input type="text" id="name" name="name" value="John Doe">
<br><br>
<label for="email">Email:</label><br>
<input type="email" id="email" name="email" value="john.doe@example.com">
<br><br>
<input type="submit" value="Submit">
</form>
Browser Support
The following table will show you the current browser support for the HTML value
Attribute.
Desktop | |||||
Yes | Yes | Yes | Yes | Yes |
Tablets / Mobile | |||||
Yes | Yes | Yes | Yes | Yes | Yes |
Last updated by CSSPortal on: 30th March 2024