KDOC 666: HTMLのbuttonはtypeを書かないとフォームを送信する

この文書のステータス

  • 作成
    • 2026-10-17 貴島
  • レビュー
    • 2026-10-17 貴島

概要

HTMLでフォームの中に置いた <button> は、 type 属性を書かないと、フォームを送信するボタンになる。JavaScript の処理を呼ぶきっかけのつもりで置いても、押すと送信が走り、ふつうは画面が遷移する。

<button>ボタン</button>
<button type="submit">ボタン</button>

送信させないときは、 type="button" を指定する。

<button type="button">ボタン</button>

仕様では、 type を書かないときと、不正な値を書いたときは、Auto という状態になる。

The attribute’s missing value default and invalid value default are both the Auto state.

HTML Standard - The button element

Auto 状態のボタンは、 command 属性と commandfor 属性のどちらもなく、親が select 要素でなければ、送信ボタンになる。ふつうにフォームの中へ置いた <button> はこの条件にすべて当てはまるので、送信ボタンとして動く。

A button element is said to be a submit button if any of the following are true:

  • the type attribute is in the Auto state, both the command and commandfor content attributes are not present, and the parent node is not a select element; or
  • the type attribute is in the Submit Button state.

HTML Standard - The button element

関連

なし。