Definition and Usage
- Controls
- Refers to elements that allow users to interact with a web page.
The<input>tag, along with the<button>,<textarea>, and<select>tags, are typical control elements that allow users to enter data, make selections, or click.
Note!
Resetting the values of all controls in a form means returning the values entered or set by the user to their initial values. It does not mean clearing all input values.
Basic Example
Resetting When There Is No Initial Value
In the following example, no value is set for <input type="text">. In other words, its value is empty. After entering a value, when the user clicks <input type="reset">, the <input type="text"> value resets to its initial empty state.
<form action="submit_url">
<label for="user-name">Name</label>
<input type="text" id="user-name" name="user-name">
<input type="reset">
</form>
Resetting When There Is an Initial Value
Unlike the example above, the following example uses the value attribute to set the initial value of <input type="text"> to John Doe. In this case, clicking <input type="reset"> without changing the value will leave John Doe unchanged. However, if the user changes John Doe to a different value and clicks <input type="reset">, the field resets to its initial value, John Doe.
<form action="submit_url">
<label for="user-name">Name</label>
<input type="text" id="user-name" name="user-name" value="John Doe">
<input type="reset">
</form>
The implicit role value of <input type="reset"> is button.
Using Related Attributes
Let's learn about the attributes related to <input type="reset">.
value Attribute
The value attribute specifies the string to be used as the button's label.
If a string for the button's label is not specified using the value attribute, the browser's default label is displayed.
value attribute
<input type="reset" value="String used as the label">
value attribute
<input type="reset">
disabled Attribute
Use the disabled attribute to disable a button. It prevents user interactions with the button, such as pressing or clicking.
It is a Boolean attribute, meaning you only need to include the attribute name without specifying a value.
<input type="reset" value="Disabled Button" disabled>
Styling Limitations
The type="reset" of the <input> tag is fully effective for resetting all input values in the form that contains the element, but HTML also provides <button type="reset">, which has the same functionality.
The <input> tag is a void element, meaning it cannot have any content and does not have a closing tag (</input>).
The <button> tag has a closing tag (</button>), allowing it to contain child content.
Because it can hold inner content, you can include HTML elements or images within its label, giving you far more styling flexibility.
<style>
button {
color: inherit;
text-decoration: none;
padding: 0.5em 1em;
background-color: #fff;
border: 1px solid #777;
border-radius: 0.5em;
display: inline-flex;
align-items: center;
}
/* The input tag cannot use
::before or ::after. */
button::before {
content: "";
display: inline-flex;
width: 0.5em;
height: 0.5em;
border-left: 1px solid black;
border-bottom: 1px solid black;
transform: rotateZ(45deg);
margin-right: 0.2em;
}
</style>
<button type="reset">Reset</button>
Browser Compatibility
| Attribute |
Desktop Chrome
|
Desktop Edge
|
Desktop Firefox
|
Safari
|
|---|---|---|---|---|
<input type="reset"> |
1 | 12 | 1 | 1 |
disabled
|
1 | 12 | 1 | 1 |
Specifications
| Specification | |
|---|---|
<input type="reset">
|
HTML Standard #reset-button-state-(type=reset) |