HTML button element

Reference for the HTML button element: default type submit, relationship to a form, type=button versus submit and reset, and disabled (buttons have no readonly).

The button element is a labelled control that can contain phrasing content (text, images, and similar), unlike input type="submit". It must not contain interactive content, and it must not be nested inside an a or another button. Both start and end tags are required.

The missing value default and invalid value default for type are submit. A button with no type attribute is a submit button. If it is associated with a form, activating it submits that form. This is a frequent source of accidental submissions.

Examples are markup only. Click handling, form submission, and focus were not executed in a browser.

Official sources: MDN <button> element and the WHATWG HTML Living Standard. Fragments were checked with Python 3.13 html.parser. That parser builds an element tree; it is not a WHATWG conformance checker, and this is not a browser or accessibility test.

HTML tag catalog → · HTML tutorial overview →

Types and the default submit button

type="submit" submits the associated form. type="reset" resets that form's controls to their initial values. type="button" does not submit or reset; any action needs script that this page does not run.

Because the default is submit, write type="button" when the control must not submit. A submit button may also have name and value; if that button is used to submit, those fields become successful controls, which is useful for more than one submit action (for example, "Save" versus "Save draft").

Default submit, reset, type=button, and a named submit

<button>
<button type="submit" name value>
<button type="reset">
<button type="button">
<button type="submit" disabled>

A button with no type is a submit button and will submit its form.

AttributeDescription
typesubmit (default), reset, or button. An invalid type is treated as submit.
name and valueIf a submit button is used to submit the form, its name and value are included in the submission.
formThe id of a form in the same document, used when the button is not a descendant of that form.
formaction, formmethod, formenctype, formtarget, formnovalidateSubmit-button overrides for the associated form's action, method, enctype, target, and novalidate. They apply only when this button submits.
  • The Preview button has type="button" and no script. It will not submit the form. No third-party action is present.
html
<form>
  <p>
    <label for="name">Name</label>
    <input id="name" name="name" type="text">
  </p>
  <button>Save</button>
  <button type="reset">Reset</button>
  <button type="button">Preview</button>
  <button type="submit" name="intent" value="draft">Save draft</button>
  <button type="submit" disabled>Saving</button>
</form>

What this markup means

The first button has no type, so it is a submit button labelled Save. Reset restores initial control values. Preview does not submit. Save draft is another submit button whose name and value can distinguish the intent if it is the button used to submit. The disabled Saving button is not successful and cannot be activated.

Related: Tag catalog: <button>, <form>, <input>

MDN documentation → · WHATWG HTML Standard →

Relationship to a form

A button is associated with its nearest ancestor form, or with the form whose id matches the button's form attribute. A submit or reset button that is not associated with a form has no form to submit or reset.

Do not nest a button inside an a, or an a inside a button. Use a for navigation and button for actions, including form submission.

disabled, not readonly

button supports disabled. A disabled button is not a successful control and is not ordinarily activatable or focusable. button does not have a readonly attribute; that distinction belongs to input (and textarea). Do not expect readonly on a button to do anything useful, because the attribute is not part of the button element's definition.