<button>
HTML <button> Tag
Instance
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文网(php.cn)</title> </head> <body> <button type="button" onclick="alert('你好,世界!')">点我!</button> </body> </html>
Run Example»
Click the "Run Instance" button to view the online instance
Browser support
All major browsers support the <button> tag.
Tag definition and usage instructions
<button> The tag defines a button.
Inside the <button> element, you can place content, such as text or images. This is the difference between this element and buttons created using the <input> element.
Tip: Always specify the type attribute for <button> elements. Different browsers use different default values for the type attribute of the <button> element.
Tips and Notes
Notes: If you use the <button> element in an HTML form, different browsers may submit different button values. Use <input> to create buttons in HTML forms.
Differences between HTML 4.01 and HTML5
New attributes in HTML5: autofocus, form, formaction, formenctype, formmethod, formnovalidate, and formtarget.
Attribute
New: New attribute in HTML5.
Properties | Value | Description |
---|---|---|
autofocusNew | autofocus | Specifies that the button should automatically gain focus when the page loads. |
disabled | disabled | Specifies that the button should be disabled. |
formNew | form_id | Specifies that the button belongs to one or more forms. |
formactionNew | URL | Specifies where to send form data when the form is submitted . Override the action attribute of the form element. This attribute is used with type="submit". |
formenctypeNew | application/x-www-form-urlencoded multipart/form-data text/plain | Specifies how to encode form data before sending it to the server. Override the enctype attribute of the form element. This attribute is used with type="submit". |
formmethodNew | get post | Specifies the HTTP method used to send form data. Override the method attribute of the form element. This attribute is used with type="submit". |
formnovalidateNew | formnovalidate | If this attribute is used, no validation will be performed when submitting the form. Override the novalidate attribute of the form element. This attribute is used with type="submit". |
formtargetNew | _blank _self _parent _top framename | Specifies where to open the action URL. Override the target attribute of the form element. This attribute is used with type="submit". |
name | name | Specifies the name of the button. |
type | button reset Submit | Specifies the type of button. |
value | text | Specifies the initial value of the button. Can be modified by script. |
Global attributes
<button> tag supports global attributes of HTML.
Event attributes
<button> tag supports HTML event attributes.
Related articles
HTML DOM Reference Manual: Button object