Warning Button inside a form with no type attribute

Why a <button> with no type attribute defaults to type="submit" inside a form, and the accidental submissions that causes.

The validator warns about any <button> inside a <form> that has no explicit type attribute.

Example

<!-- Flagged: this button submits the form, maybe unintentionally -->
<form>
  <input type="text" name="q">
  <button>Clear</button>
</form>

<!-- Right: be explicit -->
<button type="button">Clear</button>
<button type="submit">Search</button>

Why it matters

A <button> element defaults to type="submit" whenever its type attribute is omitted — this is spec-defined behavior, not a bug, but it surprises a lot of developers who assume a bare <button> is inert until wired up with JavaScript. The common failure mode: a "clear," "cancel," or icon-only button is added inside a form for some other purpose, gets no explicit type, and ends up submitting the form whenever it's clicked — often triggering a page reload or an unwanted API call. This is especially easy to miss during development if the form doesn't yet have a working submit handler to make the accidental submission obvious.

Frequently asked questions

What are the valid values for button type?

submit (the default), button (does nothing on its own — for JavaScript-driven actions), and reset (resets form fields to their default values, rarely used today).

Does this apply to buttons outside a <form>?

No — the validator only flags buttons that are descendants of a form element, since a button with no type outside any form has no submit behavior to accidentally trigger.