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)

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay