Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

HTMLButtonElement.type — button action type

HTMLButtonElement.type reads a button's effective type and writes its type attribute. It distinguishes submit, reset, and button; a missing or invalid value does not always mean submit.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

button.type
button.type = "submit"; // or "reset", "button"

HTMLButtonElement.type is a writable string property of the browser DOM, defined by the HTML Living Standard rather than ECMAScript. submit means submitting the associated form, reset means resetting it, and button means no default submission or reset. Event handlers and declarative actions remain possible.

Writing sets the type attribute. Reading returns the effective lowercase value, not necessarily the raw attribute text. Thus, after assigning "RESET", the property returns "reset", but getAttribute("type") returns "RESET".

A missing or invalid attribute value means the Auto state. In that state, reading returns "submit" if neither command nor commandfor is present and the parent is not select; otherwise it returns "button". Explicit "submit" does not depend on these conditions.

For a button that must not submit a form, explicitly set type = "button". The property does not itself activate the button. The example requires a browser DOM; the presence of Node 24 does not establish support for this API.

Examples

const button = document.createElement("button");
console.log(button.type);

button.type = "RESET";
console.log(button.type, button.getAttribute("type"));

button.type = "unknown";
console.log(button.type, button.getAttribute("type"));

button.type = "button";
console.log(button.type);

Result

submit
reset RESET
submit unknown
button

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources