Missing Button Type Attribute
A <button> element without a type attribute defaults to type="submit". This means any button inside a form will submit the form when clicked, even if that wasn't intended. This is a common source of bugs where clicking a 'Cancel' or 'Clear' button accidentally submits the form.
Why It Matters
Unexpected form submissions frustrate users and can cause data loss. For accessibility, screen readers announce the button type, and a mislabeled button type gives incorrect information about what the button does. It's flagged by most HTML validators and accessibility auditing tools.
Common Causes
- Writing <button>Cancel</button> inside a form and not realizing the default type is submit.
- Adding a JavaScript-only action button (toggle, open modal) inside a form without setting type="button".
- Copying button markup from a context outside a form, where the implicit submit had no visible effect.
Code Examples
<form> <input type="text" name="search"> <!-- This button submits the form! --> <button>Clear</button> <button>Submit</button> </form>
<form> <input type="text" name="search"> <button type="button">Clear</button> <button type="submit">Submit</button> <button type="reset">Reset</button> </form>
How to Fix
- 1Always add an explicit type attribute to every <button> element.
- 2Use type="submit" for buttons that should submit a form.
- 3Use type="button" for buttons that trigger JavaScript actions without submitting.
- 4Use type="reset" only for buttons that should reset form fields to their default values.
Frequently Asked Questions
What type does a button default to if I omit it?
Is a missing button type an accessibility issue or a bug?
Does this apply to <input type="submit"> too?
Check Your Accessibility Now
Our accessibility checker detects this issue automatically.
Open Accessibility CheckerCloudways · Managed Cloud Hosting
Fix accessibility errors, then deploy on Cloudways managed cloud (AWS, GCP, DigitalOcean).
Free 3-day trial · 30% off 3 months + free site migration with code MIGRATE303
Related Accessibility Errors
Missing Form Labels
Missing form labels leave inputs unreadable to screen readers and hurt usability. Learn how to label every form field correctly for WCAG compliance, step by step.
Missing Alt Text on Images
Missing alt text hides images from screen readers and Google Images. Learn why alt attributes matter for accessibility and SEO, and how to write them well.
Empty Heading Elements
An empty heading breaks your document outline and confuses screen reader navigation. Learn how to find and fix empty H1 to H6 elements for accessible structure.