/

How to Reset a Form

How to Reset a Form

One common requirement on a web page that contains a form is to reset it back to its original state. In the past, many forms included a “reset” button, but nowadays it is used less frequently.

The reset button is represented by an input element with the type attribute set to “reset”:

1
<input type="reset">

However, it is also possible to reset a form programmatically using JavaScript. All you need is a reference to the form element:

1
const form = document.querySelector('form');

Then, you can simply call the reset() method:

1
form.reset();

This will clear all the elements within the form, reverting them back to their original state.

Tags: form, reset, JavaScript