English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML Reference Manual

HTML Tag Reference

HTML: <button> Tag

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.

Online Example

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 ‹/›

Browser compatibility

IEFirefoxOperaChromeSafari

All major browsers support the <button> tag.

Definition and usage of the 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.

Tips and Notes

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.

HTML 4.01 with HTML5differences

HTML5 new attributes: autofocus, form, formaction, formenctype, formmethod, formnovalidate, and formtarget.

Attribute

New :HTML5 new attribute.

AttributeValueDescription
autofocusHTML5autofocusSpecify that the button should automatically receive focus when the page is loaded.
disableddisabledSpecify that the button should be disabled.
formHTML5form_idSpecify that the button belongs to one or more forms.
formactionHTML5URLSpecify 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".
formenctypeHTML5application/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".
formmethodHTML5get
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".
formnovalidateHTML5formnovalidateIf 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".
Specifies the name or keyword to display the response after submitting the form.It can be one of the following values: _self, _blank, _parent, _top

_self-Indicates that the response is loaded into the current frame or context
_blank-Indicates that the response is loaded into a new window or context
_parent-Indicates that the response is loaded into the parent frame or context
_top-Indicates that the response is loaded into the complete original window

namenameSpecifies the name of the button.
type

submit 

reset

button

Specifies the type of the button.
Submit-Indicates that the button submits form data to the server (if type is not specified, it is the default value)
Reset-Indicates that the button resets all controls
Button-Indicates that the button has no default behavior

valuetextSpecifies the initial value of the button. Can be modified by script.

Global Attributes

Supports <button> tag Global Attributes of HTML.

Event Attributes

Supports <button> tag HTML Event Attributes.

Related Articles

HTML DOM Reference Manual: Button Object