How to prevent buttons from submitting forms with HTML?

Spread the love

Sometimes, we want to prevent buttons from submitting forms with HTML.

In this article, we’ll look at how to prevent buttons from submitting forms with HTML.

How to prevent buttons from submitting forms with HTML?

To prevent buttons from submitting forms with HTML, we can set the type attribute of a button to button.

For instance, we write

<button type="button">Button</button>

to add a button with type attribute set to button to stop it from submitting the form that it’s in when we click on it.

Conclusion

To prevent buttons from submitting forms with HTML, we can set the type attribute of a button to button.

Leave a Reply

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