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.
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.
Check Your Accessibility Now
Our accessibility checker detects this issue automatically.
Open Accessibility CheckerHostinger — Fast & Affordable Web Hosting
Deploy accessible, validated code on reliable hosting.
Related Accessibility Errors
Missing Form Labels
Form inputs without labels are inaccessible to screen readers. Learn how to properly label form fields for WCAG compliance.
Missing Alt Text on Images
Learn why alt text is required on images, how it affects accessibility and SEO, and how to write effective alt attributes.
Empty Heading Elements
Empty heading tags break document structure and confuse screen readers. Learn how to fix empty H1-H6 elements.