HTML - <button>

The HTML <button> Element represents a clickable button.

Example

 

HTML
<button name="button">Click me</button>

Please note that this button has CSS applied.

Description  

The HTML <button> Element represents a clickable button.

Content categories Flow content, phrasing content, Interactive content, listed, labelable, and submittable form-associated element, palpable content.
Permitted content Phrasing content.
Tag omission None, both the starting and ending tag are mandatory. 
Permitted parent elements Any element that accepts phrasing content.
DOM interface HTMLButtonElement
Element type Inline

Browser Compatibility  

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 1.0 1.0 (1.7 or earlier) (Yes) (Yes) (Yes)
formaction attribute 9.0 4.0 (2.0) 10 ? ?
formenctype attribute 9.0 4.0 (2.0) 10 10.6 ?
formmethod attribute 9.0 4.0 (2.0) 10 ? ?
autofocus attribute 5.0 4.0 (2.0) 10 9.6 5.0
menu value for type attribute No support No support[1] No support No support ?
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) 1.0 (1.0) (Yes) (Yes) (Yes)
formaction attribute ? 4.0 (2.0) ? ? ?
formenctype attribute ? 4.0 (2.0) ? ? ?
formmethod attribute ? 4.0 (2.0) ? ? ?
menu value for type attribute ? ? ? ? ?

[1] Gecko does not implement this feature yet. See bug 1241353.

Clicking and focus

Whether clicking on a <button> causes it to (by default) become focused varies by browser and OS. The results for <input> of type="button" and type="submit" were the same.

Does clicking on a <button> give it the focus?
Desktop Browsers Windows 8.1 OS X 10.9
Firefox 30.0 Yes No (even with a tabindex)
Chrome 35 Yes Yes
Safari 7.0.5 N/A No (even with a tabindex)
Internet Explorer 11 Yes N/A
Presto (Opera 12) Yes Yes
Does tapping on a <button> give it the focus?
Mobile Browsers iOS 7.1.2 Android 4.4.4
Safari Mobile No (even with a tabindex) N/A
Chrome 35 No (even with a tabindex) Yes

Notes  

<button> elements are much easier to style than <input> elements. You can add inner HTML content (think <em>, <strong> or even <img>), and make use of :after and :before pseudo-element to achieve complex rendering while <input> only accepts a text value attribute.

IE7 has a bug where when submitting a form with <button type="submit" name="myButton" value="foo">Click me</button>, the POST data sent will result in myButton=Click me instead of myButton=foo.
IE6 has an even worse bug where submitting a form through a button will submit ALL buttons of the form, with the same bug as IE7.
This bug has been fixed in IE8.

Firefox will add, for accessibility purposes, a small dotted border on a focused button. This border is declared through CSS, in the browser stylesheet, but you can override it if necessary to add your own focused style using button::-moz-focus-inner { }

Firefox will, unlike other browsers, by default, persist the dynamic disabled state of a <button> across page loads. Setting the value of the autocomplete attribute to off disables this feature. See bug 654072.

Firefox <35 for Android sets a default background-image gradient on all buttons (see bug 763671). This can be disabled using background-image: none.

See Also  

Other elements that are used for creating forms: <form>, <datalist>, <fieldset>, <input>,<keygen>, <label>, <legend>, <meter>, <optgroup>, <option>, <output>, <progress>, <select>, <textarea>.

Specifications  

Specification Status Comment
WHATWG HTML Living Standard
The definition of '<button>' in that specification.
Living Standard  
HTML5
The definition of '<button>' in that specification.
Recommendation  
HTML 4.01 Specification
The definition of '<button>' in that specification.
Recommendation  

License

© 2016 Mozilla Contributors
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-us/docs/web/html/element/button

Element Forms HTML HTML forms Intermediate Reference Web