HTML Code to Make Button Not to Submit Form

HTML Code to Make Button Not to Submit Form

The default type attribute of the button element is “submit”. That means it submits the form and refreshes the page when you click the button.

<button> Click </button>

If you add this button inside the HTML form, the form gets submitted every time the user clicks on the button.

If you want to avoid refreshing the page or not submitting the form, change the default type attribute value to “button”.

<button type="button"> Click </button>

This is a handy feature when you want to create the button inside an HTML form and don’t want to submit the form by clicking the button.

Also, check best programming practices for web form design.

If you have any doubt, write in the comment section below.

Leave a Reply

Your email address will not be published. Required fields are marked *