Rule
Button types in forms
Buttons inside forms should declare their type.
- Rule
button-type- Type
- Best practice, not a WCAG requirement. It runs when Best practices is switched on.
- Severity
- Minor
What it checks
A <button> inside a <form> with no type, or an empty one, is a submit button by default. The rule fails such a button when the form holds other buttons, because one meant only to clear a field or open a panel will submit the form instead.
A form whose only button has no type passes. That button is the form's default and submitting is its whole job, so nothing happens by accident. An unexpected submission can move focus or reload the page, which is hard to follow without sight of the screen.
Example
Fails
<form action="/search">
<label for="q">Search</label>
<input id="q" name="q">
<button>Clear</button>
<button>Search</button>
</form>
Passes
<form action="/search">
<label for="q">Search</label>
<input id="q" name="q">
<button>Search</button>
</form>
The engine is tested against both examples.
How to fix it
Add type="button" to buttons that run script, and type="submit" to the one that sends the form.
Check your own pages
This rule runs in every pour audit: the browser extension, the bookmarklet, the command line and the editor. Get pour, free.