Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 1072860 of <button>

  • Revision slug: Web/HTML/Element/button
  • Revision title: <button>
  • Revision id: 1072860
  • Created:
  • Creator: Sebastianz
  • Is current revision? No
  • Comment Added 'menu' value to 'type' attribute

Revision Content

Summary

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 {{no_tag_omission}} 
Permitted parent elements Any element that accepts phrasing content.
DOM interface {{domxref("HTMLButtonElement")}}
Element type Inline

Attributes

This element includes the global attributes.

{{htmlattrdef("autofocus")}} {{HTMLVersionInline(5)}}
This Boolean attribute lets you specify that the button should have input focus when the page loads, unless the user overrides it, for example by typing in a different control. Only one form-associated element in a document can have this attribute specified.
{{htmlattrdef("autocomplete")}} {{non-standard_inline}}
The use of this attribute on a {{HTMLElement("button")}} is nonstandard and Firefox-specific. By default, unlike other browsers, Firefox persists the dynamic disabled state of a {{HTMLElement("button")}} across page loads. Setting the value of this attribute to off (i.e. autocomplete="off") disables this feature. See {{bug(654072)}}.
{{htmlattrdef("disabled")}}

This Boolean attribute indicates that the user cannot interact with the button. If this attribute is not specified, the button inherits its setting from the containing element, for example {{HTMLElement("fieldset")}}; if there is no containing element with the disabled attribute set, then the button is enabled.

Firefox will, unlike other browsers, by default, persist the dynamic disabled state of a {{HTMLElement("button")}} across page loads. Use the {{htmlattrxref("autocomplete","button")}} attribute to control this feature.

{{htmlattrdef("form")}} {{HTMLVersionInline(5)}}
The form element that the button is associated with (its form owner). The value of the attribute must be the id attribute of a {{HTMLElement("form")}} element in the same document. If this attribute is not specified, the <button> element will be associated to an ancestor {{HTMLElement("form")}} element, if one exists. This attribute enables you to associate <button> elements to {{HTMLElement("form")}} elements anywhere within a document, not just as descendants of {{HTMLElement("form")}} elements.
{{htmlattrdef("formaction")}} {{HTMLVersionInline(5)}}
The URI of a program that processes the information submitted by the button. If specified, it overrides the {{htmlattrxref("action","form")}} attribute of the button's form owner.
{{htmlattrdef("formenctype")}} {{HTMLVersionInline(5)}}
If the button is a submit button, this attribute specifies the type of content that is used to submit the form to the server. Possible values are:
  • application/x-www-form-urlencoded: The default value if the attribute is not specified.
  • multipart/form-data: Use this value if you are using an {{HTMLElement("input")}} element with the {{htmlattrxref("type","input")}} attribute set to file.
  • text/plain

If this attribute is specified, it overrides the {{htmlattrxref("enctype","form")}} attribute of the button's form owner.

{{htmlattrdef("formmethod")}} {{HTMLVersionInline(5)}}
If the button is a submit button, this attribute specifies the HTTP method that the browser uses to submit the form. Possible values are:
  • post: The data from the form is included in the body of the form and is sent to the server.
  • get: The data from the form are appended to the form attribute URI, with a '?' as a separator, and the resulting URI is sent to the server. Use this method when the form has no side-effects and contains only ASCII characters.

If specified, this attribute overrides the {{htmlattrxref("method","form")}} attribute of the button's form owner.

{{htmlattrdef("formnovalidate")}} {{HTMLVersionInline(5)}}
If the button is a submit button, this Boolean attribute specifies that the form is not to be validated when it is submitted. If this attribute is specified, it overrides the {{htmlattrxref("novalidate","form")}} attribute of the button's form owner.
{{htmlattrdef("formtarget")}} {{HTMLVersionInline(5)}}
If the button is a submit button, this attribute is a name or keyword indicating where to display the response that is received after submitting the form. This is a name of, or keyword for, a browsing context (for example, tab, window, or inline frame). If this attribute is specified, it overrides the {{htmlattrxref("target", "form")}} attribute of the button's form owner. The following keywords have special meanings:
  • _self: Load the response into the same browsing context as the current one. This value is the default if the attribute is not specified.
  • _blank: Load the response into a new unnamed browsing context.
  • _parent: Load the response into the parent browsing context of the current one. If there is no parent, this option behaves the same way as _self.
  • _top: Load the response into the top-level browsing context (that is, the browsing context that is an ancestor of the current one, and has no parent). If there is no parent, this option behaves the same way as _self.
{{htmlattrdef("name")}}
The name of the button, which is submitted with the form data.
{{htmlattrdef("type")}}
The type of the button. Possible values are:
  • submit: The button submits the form data to the server. This is the default if the attribute is not specified, or if the attribute is dynamically changed to an empty or invalid value.
  • reset: The button resets all the controls to their initial values.
  • button: The button has no default behavior. It can have client-side scripts associated with the element's events, which are triggered when the events occur.
  • menu: The button opens a popup menu defined via its designated {{HTMLElement("menu")}} element.
{{htmlattrdef("value")}}
The initial value of the button.

Example

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

{{ EmbedLiveSample('Example', 200, 64) }}

Please note that this button has CSS applied.

Specifications

Specification Status Comment
{{SpecName('HTML WHATWG', 'the-button-element.html#the-button-element', '<button>')}} {{Spec2('HTML WHATWG')}}  
{{SpecName('HTML5 W3C', 'forms.html#the-button-element', '<button>')}} {{Spec2('HTML5 W3C')}}  
{{SpecName('HTML4.01', 'interact/forms.html#h-17.5', '<button>')}} {{Spec2('HTML4.01')}}  

Browser compatibility

{{CompatibilityTable}}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 1.0 {{CompatGeckoDesktop("1.0")}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}}
formaction attribute 9.0 {{CompatGeckoDesktop("2.0")}} 10 {{CompatUnknown}} {{CompatUnknown}}
formenctype attribute 9.0 {{CompatGeckoDesktop("2.0")}} 10 10.6 {{CompatUnknown}}
formmethod attribute 9.0 {{CompatGeckoDesktop("2.0")}} 10 {{CompatUnknown}} {{CompatUnknown}}
autofocus attribute 5.0 {{CompatGeckoDesktop("2.0")}} 10 9.6 5.0
menu value for type attribute {{CompatNo}} {{CompatNo}}[1] {{CompatNo}} {{CompatNo}} {{CompatUnknown}}
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{CompatVersionUnknown}} {{CompatGeckoMobile("1.0")}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}}
formaction attribute {{CompatUnknown}} {{CompatGeckoMobile("2.0")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
formenctype attribute {{CompatUnknown}} {{CompatGeckoMobile("2.0")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
formmethod attribute {{CompatUnknown}} {{CompatGeckoMobile("2.0")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
menu value for type attribute {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}

[1] Gecko does not implement this feature yet. See {{bug("1241353")}}.

Clicking and focus

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

Does clicking on a {{HTMLElement("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 {{HTMLElement("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 {{HTMLElement("input")}} elements. You can add inner HTML content (think <em>, <strong> or even <img>), and make use of {{Cssxref(":after")}} and {{Cssxref(":before")}} pseudo-element to achieve complex rendering while {{HTMLElement("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{{cssxref("::-moz-focus-inner")}} { }

Firefox will, unlike other browsers, by default, persist the dynamic disabled state of a {{HTMLElement("button")}} across page loads. Setting the value of the {{htmlattrxref("autocomplete","button")}} attribute to off disables this feature. See {{bug(654072)}}.

Firefox <35 for Android sets a default {{ cssxref("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: {{HTMLElement("form")}}, {{HTMLElement("datalist")}}, {{HTMLElement("fieldset")}}, {{HTMLElement("input")}},{{HTMLElement("keygen")}}, {{HTMLElement("label")}}, {{HTMLElement("legend")}}, {{HTMLElement("meter")}}, {{HTMLElement("optgroup")}}, {{HTMLElement("option")}}, {{HTMLElement("output")}}, {{HTMLElement("progress")}}, {{HTMLElement("select")}}, {{HTMLElement("textarea")}}.

{{HTMLRef}}

Revision Source

<h2 id="Summary">Summary</h2>

<p>The <strong>HTML <em><code>&lt;button&gt;</code></em> Element</strong> represents a clickable button.</p>

<table class="properties">
 <tbody>
  <tr>
   <th scope="row"><a href="/en-US/docs/HTML/Content_categories" title="HTML/Content_categories">Content categories</a></th>
   <td><a href="/en-US/docs/HTML/Content_categories#Flow_content" title="HTML/Content categories#Flow content">Flow content</a>, <a href="/en-US/docs/HTML/Content_categories#Phrasing_content" title="HTML/Content categories#Phrasing content">phrasing content</a>, <a href="/en-US/docs/HTML/Content_categories#Interactive_content" title="HTML/Content categories#Interactive content">Interactive content</a>, <a href="/en-US/docs/HTML/Content_categories#Form_listed" title="HTML/Content categories#Form listed">listed</a>, <a href="/en-US/docs/HTML/Content_categories#Form_labelable" title="HTML/Content categories#Form labelable">labelable</a>, and <a href="/en-US/docs/HTML/Content_categories#Form_submittable" title="HTML/Content categories#Form submittable">submittable</a>&nbsp;<a href="/en-US/docs/HTML/Content_categories#Form-associated_" title="HTML/Content categories#Form-associated ">form-associated</a> element, palpable content.</td>
  </tr>
  <tr>
   <th scope="row">Permitted content</th>
   <td><a href="/en-US/docs/HTML/Content_categories#Phrasing_content" title="HTML/Content_categories#Phrasing_content">Phrasing content</a>.</td>
  </tr>
  <tr>
   <th scope="row">Tag omission</th>
   <td>{{no_tag_omission}}&nbsp;</td>
  </tr>
  <tr>
   <th scope="row">Permitted parent elements</th>
   <td>Any element that accepts <a href="/en-US/docs/HTML/Content_categories#Phrasing_content" title="HTML/Content_categories#Phrasing_content">phrasing content</a>.</td>
  </tr>
  <tr>
   <th scope="row">DOM interface</th>
   <td>{{domxref("HTMLButtonElement")}}</td>
  </tr>
  <tr>
   <th scope="row">Element type</th>
   <td>Inline</td>
  </tr>
 </tbody>
</table>

<h2 id="Attributes">Attributes</h2>

<p><span style="line-height:21px">This element includes the&nbsp;</span><a href="https://developer.mozilla.org/en-US/docs/HTML/Global_attributes" style="line-height: 21px;" title="HTML/Global attributes">global attributes</a><span style="line-height:21px">.</span></p>

<dl>
 <dt>{{htmlattrdef("autofocus")}} {{HTMLVersionInline(5)}}</dt>
 <dd>This Boolean attribute lets you specify that the button should have input focus when the page loads, unless the user overrides it, for example by typing in a different control. Only one form-associated element in a document can have this attribute specified.</dd>
 <dt>{{htmlattrdef("autocomplete")}} {{non-standard_inline}}</dt>
 <dd>The use of this attribute on a {{HTMLElement("button")}} is nonstandard and Firefox-specific. By default, unlike other browsers, <a href="https://stackoverflow.com/questions/5985839/bug-with-firefox-disabled-attribute-of-input-not-resetting-when-refreshing">Firefox persists the dynamic disabled state</a> of a {{HTMLElement("button")}} across page loads. Setting the value of this attribute to <code>off</code> (i.e. <code>autocomplete="off"</code>) disables this feature. See {{bug(654072)}}.</dd>
 <dt>{{htmlattrdef("disabled")}}</dt>
 <dd>
 <p>This Boolean attribute indicates that the user cannot interact with the button. If this attribute is not specified, the button inherits its setting from the containing element, for example {{HTMLElement("fieldset")}}; if there is no containing element with the <strong>disabled</strong> attribute set, then the button is enabled.</p>

 <p>Firefox will, unlike other browsers, by default, <a href="https://stackoverflow.com/questions/5985839/bug-with-firefox-disabled-attribute-of-input-not-resetting-when-refreshing">persist the dynamic disabled state</a> of a {{HTMLElement("button")}} across page loads. Use the {{htmlattrxref("autocomplete","button")}} attribute to control this feature.</p>
 </dd>
 <dt>{{htmlattrdef("form")}} {{HTMLVersionInline(5)}}</dt>
 <dd>The form element that the button is associated with (its <em>form owner</em>). The value of the attribute must be the <strong>id</strong> attribute of a {{HTMLElement("form")}} element in the same document. If this attribute is not specified, the <code>&lt;button&gt;</code> element will&nbsp;be associated to an&nbsp;ancestor {{HTMLElement("form")}}&nbsp;element, if one exists. This attribute enables you to associate&nbsp;<code>&lt;button&gt;</code> elements to&nbsp;{{HTMLElement("form")}}&nbsp;elements anywhere&nbsp;within a document, not just as descendants of {{HTMLElement("form")}} elements.</dd>
 <dt>{{htmlattrdef("formaction")}} {{HTMLVersionInline(5)}}</dt>
 <dd>The URI of a program that processes the information submitted by the button. If specified, it overrides the {{htmlattrxref("action","form")}} attribute of the button's form owner.</dd>
 <dt>{{htmlattrdef("formenctype")}} {{HTMLVersionInline(5)}}</dt>
 <dd>If the button is a submit button, this attribute specifies the type of content that is used to submit the form to the server. Possible values are:
 <ul>
  <li><code>application/x-www-form-urlencoded</code>: The default value if the attribute is not specified.</li>
  <li><code>multipart/form-data</code>: Use this value if you are using an {{HTMLElement("input")}} element with the {{htmlattrxref("type","input")}} attribute set to <code>file</code>.</li>
  <li><code>text/plain</code></li>
 </ul>

 <p>If this attribute is specified, it overrides the {{htmlattrxref("enctype","form")}} attribute of the button's form owner.</p>
 </dd>
 <dt>{{htmlattrdef("formmethod")}} {{HTMLVersionInline(5)}}</dt>
 <dd>If the button is a submit button, this attribute specifies the HTTP method that the browser uses to submit the form. Possible values are:
 <ul>
  <li><code>post</code>: The data from the form is included in the body of the form and is sent to the server.</li>
  <li><code>get</code>: The data from the form are appended to the <strong>form</strong> attribute URI, with a '?' as a separator, and the resulting URI is sent to the server. Use this method when the form has no side-effects and contains only ASCII characters.</li>
 </ul>

 <p>If specified, this attribute overrides the {{htmlattrxref("method","form")}} attribute of the button's form owner.</p>
 </dd>
 <dt>{{htmlattrdef("formnovalidate")}} {{HTMLVersionInline(5)}}</dt>
 <dd>If the button is a submit button, this Boolean attribute specifies that the form is not to be validated when it is submitted. If this attribute is specified, it overrides the {{htmlattrxref("novalidate","form")}} attribute of the button's form owner.</dd>
 <dt>{{htmlattrdef("formtarget")}} {{HTMLVersionInline(5)}}</dt>
 <dd>If the button is a submit button, this attribute is a name or keyword indicating where to display the response that is received after submitting the form. This is a name of, or keyword for, a <em>browsing context</em> (for example, tab, window, or inline frame). If this attribute is specified, it overrides the {{htmlattrxref("target", "form")}} attribute of the button's form owner. The following keywords have special meanings:
 <ul>
  <li><code>_self</code>: Load the response into the same browsing context as the current one. This value is the default if the attribute is not specified.</li>
  <li><code>_blank</code>: Load the response into a new unnamed browsing context.</li>
  <li><code>_parent</code>: Load the response into the parent browsing context of the current one. If there is no parent, this option behaves the same way as <code>_self</code>.</li>
  <li><code>_top</code>: Load the response into the top-level browsing context (that is, the browsing context that is an ancestor of the current one, and has no parent). If there is no parent, this option behaves the same way as <code>_self</code>.</li>
 </ul>
 </dd>
 <dt>{{htmlattrdef("name")}}</dt>
 <dd>The name of the button, which is submitted with the form data.</dd>
 <dt>{{htmlattrdef("type")}}</dt>
 <dd>The type of the button. Possible values are:
 <ul>
  <li><code>submit</code>: The button submits the form data to the server. This is the default if the attribute is not specified, or if the attribute is dynamically changed to an empty or invalid value.</li>
  <li><code>reset</code>: The button resets all the controls to their initial values.</li>
  <li><code>button</code>: The button has no default behavior. It can have client-side scripts associated with the element's events, which are triggered when the events occur.</li>
  <li>menu: The button opens a popup menu defined via its designated {{HTMLElement("menu")}} element.</li>
 </ul>
 </dd>
 <dt>{{htmlattrdef("value")}}</dt>
 <dd>The initial value of the button.</dd>
</dl>

<h2 id="Example" name="Example">Example</h2>

<pre class="brush:html">
&lt;button name="button"&gt;Click me&lt;/button&gt;
</pre>

<p>{{ EmbedLiveSample('Example', 200, 64) }}</p>

<p>Please note that this button has CSS applied.</p>

<h2 id="Specifications" name="Specifications">Specifications</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('HTML WHATWG', 'the-button-element.html#the-button-element', '&lt;button&gt;')}}</td>
   <td>{{Spec2('HTML WHATWG')}}</td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td>{{SpecName('HTML5 W3C', 'forms.html#the-button-element', '&lt;button&gt;')}}</td>
   <td>{{Spec2('HTML5 W3C')}}</td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td>{{SpecName('HTML4.01', 'interact/forms.html#h-17.5', '&lt;button&gt;')}}</td>
   <td>{{Spec2('HTML4.01')}}</td>
   <td>&nbsp;</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<p>{{CompatibilityTable}}</p>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>1.0</td>
   <td>{{CompatGeckoDesktop("1.0")}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
  </tr>
  <tr>
   <td><code>formaction</code> attribute</td>
   <td>9.0</td>
   <td>{{CompatGeckoDesktop("2.0")}}</td>
   <td>10</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
  <tr>
   <td><code>formenctype</code> attribute</td>
   <td>9.0</td>
   <td>{{CompatGeckoDesktop("2.0")}}</td>
   <td>10</td>
   <td>10.6</td>
   <td>{{CompatUnknown}}</td>
  </tr>
  <tr>
   <td><code>formmethod</code> attribute</td>
   <td>9.0</td>
   <td>{{CompatGeckoDesktop("2.0")}}</td>
   <td>10</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
  <tr>
   <td><code>autofocus</code> attribute</td>
   <td>5.0</td>
   <td>{{CompatGeckoDesktop("2.0")}}</td>
   <td>10</td>
   <td>9.6</td>
   <td>5.0</td>
  </tr>
  <tr>
   <td><code>menu</code> value for <code>type</code> attribute</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}<sup>[1]</sup></td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Mobile</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatGeckoMobile("1.0")}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
  </tr>
  <tr>
   <td><code>formaction</code> attribute</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatGeckoMobile("2.0")}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
  <tr>
   <td><code>formenctype</code> attribute</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatGeckoMobile("2.0")}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
  <tr>
   <td><code>formmethod</code> attribute</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatGeckoMobile("2.0")}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
  <tr>
   <td><code>menu</code> value for <code>type</code> attribute</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<p>[1] Gecko does not implement this feature yet. See {{bug("1241353")}}.</p>

<h3 id="Clicking_and_focus">Clicking and focus</h3>

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

<table>
 <caption>Does clicking on a {{HTMLElement("button")}} give it the focus?</caption>
 <tbody>
  <tr>
   <td>Desktop Browsers</td>
   <th>Windows 8.1</th>
   <th>OS X 10.9</th>
  </tr>
  <tr>
   <th>Firefox 30.0</th>
   <td style="background-color: LawnGreen;">Yes</td>
   <td style="background-color: red;">No (even with a <code>tabindex</code>)</td>
  </tr>
  <tr>
   <th>Chrome 35</th>
   <td style="background-color: LawnGreen;">Yes</td>
   <td style="background-color: LawnGreen;">Yes</td>
  </tr>
  <tr>
   <th>Safari 7.0.5</th>
   <td style="background-color: silver;">N/A</td>
   <td style="background-color: red;">No (even with a <code>tabindex</code>)</td>
  </tr>
  <tr>
   <th>Internet Explorer 11</th>
   <td style="background-color: LawnGreen;">Yes</td>
   <td style="background-color: silver;">N/A</td>
  </tr>
  <tr>
   <th>Presto (Opera 12)</th>
   <td style="background-color: LawnGreen;">Yes</td>
   <td style="background-color: LawnGreen;">Yes</td>
  </tr>
 </tbody>
</table>

<table>
 <caption>Does tapping on a {{HTMLElement("button")}} give it the focus?</caption>
 <tbody>
  <tr>
   <td>Mobile Browsers</td>
   <th>iOS 7.1.2</th>
   <th>Android 4.4.4</th>
  </tr>
  <tr>
   <th>Safari Mobile</th>
   <td style="background-color: red;">No (even with a <code>tabindex</code>)</td>
   <td style="background-color: silver;">N/A</td>
  </tr>
  <tr>
   <th>Chrome 35</th>
   <td style="background-color: red;">No (even with a <code>tabindex</code>)</td>
   <td style="background-color: LawnGreen;">Yes</td>
  </tr>
  <tr>
  </tr>
 </tbody>
</table>

<h2 id="Notes">Notes</h2>

<p><code>&lt;button&gt;</code> elements are much easier to style than {{HTMLElement("input")}} elements. You can add inner HTML content (think <code>&lt;em&gt;</code>, <code>&lt;strong&gt;</code> or even <code>&lt;img&gt;</code>), and make use of {{Cssxref(":after")}} and {{Cssxref(":before")}} pseudo-element to achieve complex rendering while {{HTMLElement("input")}} only accepts a text value attribute.</p>

<p>IE7 has a bug where when submitting a form with <code>&lt;button type="submit" name="myButton" value="foo"&gt;Click me&lt;/button&gt;</code>, the <code>POST</code> data sent will result in <code>myButton=Click me</code> instead of <code>myButton=foo</code>.<br />
 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.<br />
 This bug has been fixed in IE8.</p>

<p>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 <code>button{{cssxref("::-moz-focus-inner")}} { }</code></p>

<p>Firefox will, unlike other browsers, by default, <a href="https://stackoverflow.com/questions/5985839/bug-with-firefox-disabled-attribute-of-input-not-resetting-when-refreshing">persist the dynamic disabled state</a> of a {{HTMLElement("button")}} across page loads. Setting the value of the {{htmlattrxref("autocomplete","button")}} attribute to <code>off</code> disables this feature. See {{bug(654072)}}.</p>

<p>Firefox &lt;35 for Android sets a default {{ cssxref("background-image") }} gradient on all buttons (see {{bug(763671)}}). This can be disabled using <code>background-image: none</code>.</p>

<h2 id="See_also">See also</h2>

<p>Other elements that are used for creating forms: {{HTMLElement("form")}}, {{HTMLElement("datalist")}}, {{HTMLElement("fieldset")}}, {{HTMLElement("input")}},{{HTMLElement("keygen")}}, {{HTMLElement("label")}}, {{HTMLElement("legend")}}, {{HTMLElement("meter")}}, {{HTMLElement("optgroup")}}, {{HTMLElement("option")}}, {{HTMLElement("output")}}, {{HTMLElement("progress")}}, {{HTMLElement("select")}}, {{HTMLElement("textarea")}}.</p>

<div>{{HTMLRef}}</div>
Revert to this revision