</>
ValidateHTML

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

Inaccessible
<form>
  <input type="text" name="search">
  <!-- This button submits the form! -->
  <button>Clear</button>
  <button>Submit</button>
</form>
Accessible
<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?
Inside a form a <button> with no type defaults to type="submit", so clicking it submits the form. This is why a Cancel or Clear button can unexpectedly send the form. Always set type="button" for non-submitting actions.
Is a missing button type an accessibility issue or a bug?
Both. Functionally it causes accidental submissions and data loss. For accessibility, the button's role and behavior should match what assistive tech announces, and an unexpected submit gives users an outcome they were not led to expect.
Does this apply to <input type="submit"> too?
An <input type="submit"> is explicit by design, so it is unambiguous. The default-type pitfall is specific to the <button> element, which is why being explicit on every <button> is the safe habit.

Check Your Accessibility Now

Our accessibility checker detects this issue automatically.

Open Accessibility Checker
Recommended

Cloudways · 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

Start free trial

Related Accessibility Errors

View all accessibility errors