HTML <button>
Tag
Example
The following code marks a button:
Browser Support
All major browsers support the <button>
tag.
Tag Definition and Usage
The <button>
tag defines a button.
Inside a <button>
element, you can put content, such as text or images. This is the difference between this element and buttons created with the <input>
element.
Tip: Always specify the type attribute for a <button>
element. Different browsers may use different default types for the <button>
element.
Tips and Notes
Note: If you use the <button>
element in an HTML form, different browsers may submit different values. Use the <input>
element to create buttons in an HTML form.
Differences Between HTML 4.01 and HTML5
New attributes in HTML5: autofocus, form, formaction, formenctype, formmethod, formnovalidate, and formtarget.
Attributes
Attribute | Value | Description |
---|---|---|
autofocus New | autofocus | Specifies that the button should automatically get focus when the page loads. |
disabled | disabled | Specifies that the button should be disabled. |
form New | form_id | Specifies one or more forms the button belongs to. |
formaction New | URL | Specifies where to send the form-data when a form is submitted. Overrides the form element's action attribute. This attribute is used with type="submit". |
formenctype New | application/x-www-form-urlencoded <br>multipart/form-data <br>text/plain | Specifies how form-data should be encoded before sending it to a server. Overrides the form element's enctype attribute. This attribute is used with type="submit". |
formmethod New | get <br>post | Specifies the HTTP method to use when sending form-data. Overrides the form element's method attribute. This attribute is used with type="submit". |
formnovalidate New | formnovalidate | Specifies that the form-data should not be validated on submission. Overrides the form element's novalidate attribute. This attribute is used with type="submit". |
formtarget New | _blank <br>_self <br>_parent <br>_top <br>framename | Specifies where to display the response that is received after submitting the form. Overrides the form element's target attribute. This attribute is used with type="submit". |
name | name | Specifies the name of the button. |
type | button <br>reset <br>submit | Specifies the type of button. |
value | text | Specifies the initial value of the button. This value can be changed by a script. |
Global Attributes
The <button>
tag supports HTML's global attributes.
Event Attributes
The <button>
tag supports HTML's event attributes.
Related Articles
HTML DOM Reference: Button Object