DEV Community

Nic
Nic

Posted on • Originally published at blog.nicm42.co.uk on

Button type button

Ive seen <button type=button> before but thought that you never need it. Turns out you do

If you have a button on the page then by default its type is button.

But if that button is inside a form then by default its type is submit.

It makes sense. A button outside of a form with a type of submit wouldn't make sense: what would it submit? Same with reset. So it makes sense that the only thing the button can do is to be a button. But if you have a form the most likely thing that button will do is to submit the form (the second most likely is to reset the form).

So if your form contains a button that doesn't submit or reset the form (as I had recently), it needs to be of type button.

Top comments (0)