Skip to content
Tutorials Center
My learning

Topics

HTML Reference ยท Forms

The <button> element

Reference for the HTML <button> element: submit, reset and plain buttons, per-button form overrides, popover and command attributes, accessibility and technical details.

The <button> element creates a clickable button. Inside a form it submits the form by default; with type="reset" it restores the form's initial values; with type="button" it does nothing on its own, so you can attach your own JavaScript. Unlike an <input type="submit">, a button can contain markup such as an icon and some text.

HTML
<button type="submit">Save changes</button>
<button type="button" id="preview">Preview</button>

Try it

Three kinds of button

Both submit buttons share the name intent, but only the one you click is sent, with its own value. That is a simple way to give one form several actions.

Attributes

Attribute Values Description
type submit, reset, button What the button does. Missing or invalid values mean submit.
name Text Name sent with the form data when this button submits the form.
value Text Value sent together with name when this button submits the form.
disabled Boolean The button can't be focused or clicked and is never sent.
form ID of a <form> Associates the button with a form elsewhere in the document.
formaction URL Overrides the form's action for submissions made with this button.
formmethod get, post, dialog Overrides the form's method.
formenctype application/x-www-form-urlencoded, multipart/form-data, text/plain Overrides the form's enctype.
formnovalidate Boolean Skips constraint validation for submissions made with this button.
formtarget _self, _blank, _parent, _top or a browsing-context name Overrides the form's target.
popovertarget ID of an element with popover Makes the button show, hide or toggle that popover.
popovertargetaction toggle (default), show, hide What popovertarget does.
commandfor ID of an element The element that receives a command when the button is clicked (newer feature).
command show-modal, close, request-close, show-popover, hide-popover, toggle-popover, or a custom --name The command to send to the commandfor element (newer feature).

The form* overrides only apply to submit buttons. It also accepts the global attributes, such as autofocus.

Usage notes

  • Always set type. A button inside a form defaults to submit, so a "Show password" or "Add row" button without type="button" will unexpectedly submit the form.
  • Use <button> for actions, <a> for navigation. If clicking takes the user to another URL, it's a link; if it does something on the current page, it's a button.
  • Don't fake buttons. A <div> with a click handler is not focusable and does not respond to Enter or Space. A real <button> gets keyboard support and the right role for free.
  • Accessible name. The button's text is its name. An icon-only button needs a name another way, for example aria-label="Close" or visually hidden text.
  • No interactive content inside. A button can't contain links, inputs, other buttons or elements with tabindex.
  • Disabled buttons are easy to miss. They are skipped by the keyboard and often low in contrast. Consider keeping the button enabled and explaining the problem when it is pressed.
  • <button> vs <input type="submit">. Both submit; the button version can hold HTML content and is easier to style. See <input> types.

Technical summary

Content categories Flow content, phrasing content, interactive content, palpable content; form-associated: listed, labelable, submittable
Permitted content Phrasing content, with no interactive content descendants and no descendants with a tabindex attribute
Tag omission None; both the start and end tags are required
Permitted parents Any element that accepts phrasing content
Implicit ARIA role button
DOM interface HTMLButtonElement
Default display inline-block

Browser support

The element and its form attributes work in every browser. popovertarget is Baseline since 2024; command and commandfor are much newer, so check current support before relying on them without a script fallback.