Preventing form submission with zero Javascript

by Eric W. Bailey published on

Want to trigger an action? Use a button element. They’re great.

Want to also prevent form submission when someone clicks that button? Put down the JavaScript, friend. I have a better suggestion:

<button type="button">
Button action goes here
</button>

And that’s it! No preventDefault() or no overwrought dependencies that will stop working without notice. Just good ol’ reliable HTML and a humble attribute.

Okay, cool, thanks!

PS from Manuel: Thank you so much to all authors for this wonderufl series of articles and thank you to all readers for reading, sharing, and commenting! Merry christmas and a happy new year! 🖤

About Eric W. Bailey

Eric is an accessibility advocate, designer, writer, developer, and speaker.

Website/Blog: ericwbailey.website