<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

1000.png

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.

PropertiesValueDescription
autofocusNew autofocusSpecifies that the button should automatically gain focus when the page loads.
disableddisabled Specifies that the button should be disabled.
formNewform_idSpecifies that the button belongs to one or more forms.
formactionNewURLSpecifies 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".
formenctypeNewapplication/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".
formmethodNewget
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".
formnovalidateNewformnovalidateIf 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".
namenameSpecifies the name of the button.
typebutton
reset
Submit
Specifies the type of button.
valuetextSpecifies 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