Get to know MDN better
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
<input> elements of type button are rendered as push buttons, which can be programmed to control custom functionality anywhere on a webpage as required when assigned an event handler function (typically for the click event).
Note: While <input> elements of type button are still perfectly valid HTML, the newer <button> element is now the favored way to create buttons. Given that a <button>'s label text is inserted between the opening and closing tags, you can include HTML in the label, even images.
An <input type="button"> elements' value attribute contains a string that is used as the button's label. The value provides the accessible description for the button.
If you don't specify a value, you get an empty button:
<input type="button"> elements have no default behavior (their cousins, <input type="submit"> and <input type="reset"> are used to submit and reset forms, respectively). To make buttons do anything, you have to write JavaScript code to do the work.
We'll begin by creating a basic button with a click event handler that starts our machine (well, it toggles the value of the button and the text content of the following paragraph):
The script gets a reference to the HTMLInputElement object representing the <input> in the DOM, saving this reference in the variable button. addEventListener() is then used to establish a function that will be run when click events occur on the button.
Keyboard shortcuts, also known as access keys and keyboard equivalents, let the user trigger a button using a key or combination of keys on the keyboard. To add a keyboard shortcut to a button — just as you would with any <input> for which it makes sense — you use the accesskey global attribute.
In this example, s is specified as the access key (you'll need to press s plus the particular modifier keys for your browser/OS combination; see accesskey for a useful list of those).
Note: The problem with the above example of course is that the user will not know what the access key is! In a real site, you'd have to provide this information in a way that doesn't interfere with the site design (for example by providing an easily accessible link that points to information on what the site access keys are).
To disable a button, specify the disabled global attribute on it, like so:
You can enable and disable buttons at run time by setting disabled to true or false. In this example our button starts off enabled, but if you press it, it is disabled using button.disabled = true. A setTimeout() function is then used to reset the button back to its enabled state after two seconds.
If the disabled attribute isn't specified, the button inherits its disabled state from its parent element. This makes it possible to enable and disable groups of elements all at once by enclosing them in a container such as a <fieldset> element, and then setting disabled on the container.
The example below shows this in action. This is very similar to the previous example, except that the disabled attribute is set on the <fieldset> when the first button is pressed — this causes all three buttons to be disabled until the two second timeout has passed.
Note: Unlike other browsers, Firefox persists the disabled state of an <input> element even after the page is reloaded. As a workaround, set the <input> element's autocomplete attribute to off. (See Firefox bug 654072 for more details.)
Buttons don't participate in constraint validation; they have no real value to be constrained.
The below example shows a very basic drawing app created using a <canvas> element and some CSS and JavaScript (we'll hide the CSS for brevity). The top two controls allow you to choose the color and size of the drawing pen. The button, when clicked, invokes a function that clears the canvas.
| Value | A string used as the button's label |
| Events | click |
| Supported common attributes | type and value |
| IDL attributes | value |
| DOM interface | HTMLInputElement |
| Methods | None |
| Implicit ARIA Role | button |
| HTML # button-state-(type=button) |
Enable JavaScript to view this browser compatibility table.
This page was last modified on Apr 22, 2026 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.