Why is this an issue?

A <button> element without an explicit type attribute defaults to type="submit" per the HTML Living Standard, but this default has not always been implemented consistently across browsers. When the button is inside a <form>, an unintended submit type causes the form to be submitted on click, even if that was not the developer’s intent. The HTML specification defines three valid type values for buttons: submit, reset, and button. Always setting the type attribute explicitly removes any ambiguity and makes each button’s purpose clear regardless of its context or the browser rendering it.

The rule also flags buttons with an invalid type value. When the value is not one of the three defined values, the browser falls back to its default behavior for buttons without a type, which creates the same hazard.

Code examples

Noncompliant code example

function SearchForm() {
  return (
    <form action="/search">
      <input type="text" name="q" />
      <button>Search</button> // Noncompliant: defaults to type="submit"
      <button onClick={handleClear}>Clear</button> // Noncompliant: defaults to type="submit"
    </form>
  );
}

Compliant solution

function SearchForm() {
  return (
    <form action="/search">
      <input type="text" name="q" />
      <button type="submit">Search</button>
      <button type="button" onClick={handleClear}>Clear</button>
    </form>
  );
}

Noncompliant code example

<button type="action">Save</button> <!-- Noncompliant: "action" is not a valid type -->

Compliant solution

<button type="submit">Save</button>

Resources

Documentation