Table of contents
1.
Introduction
2.
Definition and Usage  
3.
Syntax
4.
Examples of <input type="reset"> Usage
4.1.
Example 1: Basic Reset Button in a Form
4.2.
Example 2: Reset Button with Default Values
5.
Validation  
6.
Why Use HTML <input type="reset">?
7.
Interesting Facts about <input type="reset">
8.
Frequently Asked Questions
8.1.
What does the reset button do in HTML?
8.2.
Can a reset button be used outside a form?
8.3.
Does the reset button clear password fields?
9.
Conclusion
Last Updated: Mar 3, 2025
Medium

Reset Button in HTML

Author Gaurav Gandhi
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

The reset button in HTML is used to clear all input fields in a form and restore them to their default values. It is created using the <input type="reset"> or <button type="reset"> tag. This button is useful when users want to discard their input and start fresh. 

Reset Button in HTML

In this article, you will learn about the reset button, its syntax, attributes, and how to style it using CSS.

Definition and Usage  

A reset button in HTML is a type of input element that clears all the data entered in a form. When clicked, it resets every field in the form to its default value. This means text fields become empty, checkboxes get unchecked, radio buttons go back to their initial state, and dropdown menus return to the first option.  

To add a reset button to your form, you use the `<input>` tag with the `type="reset"` attribute. For example: 

<!DOCTYPE html>  
<html>  
<head>  
    <title>Reset Button Example</title>  
</head>  
<body>  
    <h2>Sample Form with Reset Button</h2>  
    <form action="/submit" method="post">  
        <label for="name">Enter your name:</label><br>  
        <input type="text" id="name" name="name"><br><br>  

        <label for="email">Enter your email:</label><br>  
        <input type="email" id="email" name="email"><br><br>  

        <label for="age">Enter your age:</label><br>  
        <input type="number" id="age" name="age"><br><br>  

        <label for="gender">Select your gender:</label><br>  
        <input type="radio" id="male" name="gender" value="male"> Male<br>  
        <input type="radio" id="female" name="gender" value="female"> Female<br><br>  

        <input type="submit" value="Submit">  
        <input type="reset" value="Reset">  
    </form>  
</body>  
</html>  

 

Output

Output

In this code, the `<input type="reset">` creates the reset button. When you fill out the form and click "Reset," all fields will clear instantly.  

The reset button is useful in situations where users might want to start over or correct mistakes without manually deleting everything. However, it’s important to use it wisely because accidentally clicking the reset button can erase all the information a user has entered.  

Syntax

The reset button in HTML is created using the <input> element with the type attribute set to reset. The syntax is as follows:

<input type="reset" value="Reset Form">

 

Explanation:

  • The type="reset" specifies that this input element is a reset button.
     
  • The value attribute defines the text displayed on the button.

Examples of <input type="reset"> Usage

Example 1: Basic Reset Button in a Form

<!DOCTYPE html>
<html>
<head>
    <title>Reset Button Example</title>
</head>
<body>
    <form>
        <label for="name">Name:</label>
        <input type="text" id="name" name="name">
        <br><br>
        <label for="email">Email:</label>
        <input type="email" id="email" name="email">
        <br><br>
        <input type="submit" value="Submit">
        <input type="reset" value="Reset Form">
    </form>
</body>
</html>

 

Output:

Output
  • The form contains a name and email field along with Submit and Reset buttons.
     
  • Clicking the Reset Form button will clear the entered text in both fields.

Example 2: Reset Button with Default Values

<!DOCTYPE html>
<html>
<head>
    <title>Form Reset Example</title>
</head>
<body>
    <form>
        <label for="username">Username:</label>
        <input type="text" id="username" name="username" value="JohnDoe">
        <br><br>
        <label for="age">Age:</label>
        <input type="number" id="age" name="age" value="25">
        <br><br>
        <input type="submit" value="Submit">
        <input type="reset" value="Reset">
    </form>
</body>
</html>

 

Output

Output

Explanation:

  • The fields Username and Age have default values (JohnDoe and 25).
     
  • If the user changes these values and clicks Reset, the fields return to their initial values.

Validation  

Validation is an important concept when working with forms, including those that use a reset button. While the reset button itself doesn’t perform validation, it plays a role in how users interact with validated fields. Validation ensures that the data entered into a form meets specific criteria before submission. For example, if a field requires an email address, validation will check whether the input follows the correct format (e.g., `example@domain.com`).  

When using a reset button, you need to be mindful of how it interacts with validation. If a user fills out a form incorrectly and then clicks the reset button, all their input—including invalid data—will be cleared. This can sometimes frustrate users who only wanted to fix one or two mistakes instead of starting over entirely.  

To better understand this, let’s look at an example of a form with basic HTML5 validation and a reset button:  

<!DOCTYPE html>  
<html>  
<head>  
    <title>Form Validation with Reset Button</title>  
</head>  
<body>  
    <h2>Form with Validation and Reset Button</h2>  
    <form action="/submit" method="post">  
        <label for="username">Username (required):</label><br>  
        <input type="text" id="username" name="username" required><br><br>  

        <label for="email">Email (required):</label><br>  
        <input type="email" id="email" name="email" required><br><br>  

        <label for="password">Password (minimum 6 characters):</label><br>  
        <input type="password" id="password" name="password" minlength="6" required><br><br>  

        <label for="age">Age (must be 18+):</label><br>  
        <input type="number" id="age" name="age" min="18" required><br><br>  

        <input type="submit" value="Submit">  
        <input type="reset" value="Reset">  
    </form>  
</body>  
</html>  

 

Output

Output

In this example, each input field has validation rules applied using HTML5 attributes like `required`, `minlength`, and `min`. If a user tries to submit the form without meeting these criteria, the browser will display an error message. However, clicking the reset button bypasses all validation and clears the form completely.  

To avoid frustrating users, you can add a confirmation dialog before resetting the form. This gives users a chance to decide whether they really want to clear all their input. Let’s see how you can implement this:  

<!DOCTYPE html>  
<html>  
<head>  
    <title>Reset Button with Confirmation</title>  
    <script>  
        function confirmReset() {  
            return confirm("Are you sure you want to reset the form? All data will be lost.");  
        }  
    </script>  
</head>  
<body>  
    <h2>Form with Reset Confirmation</h2>  
    <form action="/submit" method="post" onreset="return confirmReset()">  
        <label for="name">Enter your name:</label><br>  
        <input type="text" id="name" name="name"><br><br>  

        <label for="email">Enter your email:</label><br>  
        <input type="email" id="email" name="email"><br><br>  

        <input type="submit" value="Submit">  
        <input type="reset" value="Reset">  
    </form>  
</body>  
</html>  

 

Output

 

Output

In this updated code, the `onreset` attribute triggers a JavaScript function called `confirmReset()` when the reset button is clicked. This function displays a confirmation dialog box asking the user if they’re sure they want to reset the form. If the user clicks "Cancel," the form won’t reset.  

Note: This approach improves the user experience by giving them control over whether to clear their input. It also reduces the risk of accidentally losing data due to a misplaced click.  

Why Use HTML <input type="reset">?

Using a reset button in forms has multiple benefits:

  1. Quick Data Clearing: Users can clear form fields with a single click, instead of manually deleting each entry.
     
  2. Restoring Default Values: If certain fields have default values, the reset button restores them, reducing errors in form submissions.
     
  3. Better User Experience: It improves user convenience, especially in long forms, where clearing fields manually can be time-consuming.
     
  4. Error Handling: If a user enters incorrect data, they can reset the form instead of refreshing the page.

Interesting Facts about <input type="reset">

  1. Does Not Work Without a Form: The reset button only works inside a <form> tag. If used outside a form, it won’t have any effect.
     
  2. Does Not Affect Non-Form Elements: It only resets input fields, textareas, and select dropdowns but does not affect non-form elements like <p> or <div>.
     
  3. Works Differently with JavaScript: If a form is managed with JavaScript, using the reset button may not always restore expected values.
     
  4. Resets Radio and Checkbox Inputs: It will uncheck selected checkboxes and reset selected radio buttons to their default values.

Frequently Asked Questions

What does the reset button do in HTML?

The reset button clears all form fields, restoring them to their initial values.

Can a reset button be used outside a form?

No, the reset button only works inside a <form> tag; otherwise, it has no effect.

Does the reset button clear password fields?

Yes, it clears all input fields, including password fields.

Conclusion

In this article, we learned how to create a portfolio using  HTML and CSS. A portfolio website typically includes sections like About Me, Projects, Skills, and Contact. Using HTML for structure and CSS for styling, you can design a professional and responsive layout. Understanding portfolio creation helps showcase skills, attract clients, and build an online presence effectively.

Live masterclass