English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The HTML <button> tag is an element representing a clickable button, which can be used in forms or other parts of a document where a simple standard button is needed. This tag is also commonly referred to as the <button> element.
The following code marks a button:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Basic Tutorial(oldtoolbag.com)</title> </head> <body> <button type="button" onclick="alert('Hello, world!')">Click me</button> </body> </html>Test to see ‹/›
IEFirefoxOperaChromeSafari
All major browsers support the <button> tag.
The <button> tag defines a button.
Within the <button> element, you can place content, such as text or images. This is the difference between this element and the button created using the <input> element.
The HTML <button> element is located within the <body> tag.
The <button> tag cannot be placed after the <a> tag.
Tip:Always specify the type attribute for the <button> element. Different browsers use different default values for the type attribute of the <button> element.
Note:If the <button> element is used in an HTML form, different browsers may submit different button values. Please use <input> Create a button in an HTML form.
HTML5 new attributes: autofocus, form, formaction, formenctype, formmethod, formnovalidate, and formtarget.
New :HTML5 new attribute.
Attribute | Value | Description |
---|---|---|
autofocusHTML5 | autofocus | Specify that the button should automatically receive focus when the page is loaded. |
disabled | disabled | Specify that the button should be disabled. |
formHTML5 | form_id | Specify that the button belongs to one or more forms. |
formactionHTML5 | URL | Specify where to send the form data when the form is submitted. Overrides the action attribute of the form element. This attribute is used in conjunction with type="submit". |
formenctypeHTML5 | application/x-www-form-urlencoded multipart/form-data text/plain | Specify how to encode the form data before sending it to the server. Overrides the enctype attribute of the form element. This attribute is used in conjunction with type="submit". |
formmethodHTML5 | get post | Specify the HTTP method to be used for sending form data. Overrides the method attribute of the form element. This attribute is used in conjunction with type="submit". |
formnovalidateHTML5 | formnovalidate | If this attribute is used, the form will not be validated when submitted. Overrides the novalidate attribute of the form element. This attribute is used in conjunction with type="submit". |
formtargetHTML5 | _blank _self _parent _top framename | Specify where to open the action URL. Overrides the target attribute of the form element. This attribute is used in conjunction with type="submit". |
name | name | Specifies the name of the button. |
type | submit reset button | Specifies the type of the button. |
value | text | Specifies the initial value of the button. Can be modified by script. |
Supports <button> tag Global Attributes of HTML.
Supports <button> tag HTML Event Attributes.
HTML DOM Reference Manual: Button Object