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”:

<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:

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

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

form.reset();

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

Tags: form, reset, JavaScript