The HTML
<button></button> element represents a clickable button. This element must not be a descendant of an <a> element or another <button> element. If it is a descendant of a <label> element, the <button> element's id attribute must have the same value as the label's for attribute.
Attributes
| Attribute | Value | Description |
|---|---|---|
autofocus |
Boolean | This Boolean attribute lets you specify that the button should have input focus when the page loads, unless the user overrides it, for example by typing in a different control. Only one form-associated element in a document can have this attribute specified. (HTML5) |
disabled |
Boolean | This Boolean attribute indicates that the user cannot interact with the button. If this attribute is not specified, the button inherits its setting from the containing element; if there is no containing element with the disabled attribute set, then the button is enabled.
|
form |
id | The value of the attribute must be the id attribute of a <form> element in the same document. If this attribute is not specified, the <button> element must be a descendant of a <form> element. This attribute enables you to place <button> elements anywhere within a document, not just as descendants of their <form> elements. (HTML5)
|
formaction |
URI | The URI of a program that processes the information submitted by the button. If specified, it overrides the action attribute of the button's form owner. (HTML5)
|
formenctype |
application/x-www-form-urlencoded multipart/form-data text/plain |
If the button is a submit button, this attribute specifies the type of content that is used to submit the form to the server.
|
formmethod |
post get |
If the button is a submit button, this attribute specifies the HTTP method that the browser uses to submit the form. * post: The data from the form is included in the body of the form and is sent to the server.
|
formnovalidate |
Boolean | If the button is a submit button, this Boolean attribute specifies that the form is not to be validated when it is submitted. If this attribute is specified, it overrides the novalidate attribute of the button's form owner. (HTML5)
|
formtarget |
_self _blank _parent _top |
If the button is a submit button, this attribute is a name or keyword indicating where to display the response that is received after submitting the form. This is a browsing context name. If this attribute is specified, it overrides the target attribute of the button's form owner.* _self: Load the response into the same browsing context as the current one. This value is the default if the attribute is not specified.
|
name |
name | The name of the button, which is submitted with the form data. |
type |
submit reset button |
The type of the button.
|
value |
value | The initial value of the button. |
HTML example:
<button type="button"> <img src="50x50Square.png" /> Click this button. </button>
To create simpler buttons, use <input type="button" value="Text on button" />.
Rendering
The rendering of button elements, like most form elements, is heavily dependent on the configuration of the operating system. The <button> element normally looks identical to the <input> types "reset", "button" and "submit".
Typical CSS representation
button {
padding: 0px 6px 0px 6px;
border: 2px outset ButtonFace;
background-color: ButtonFace;
color: ButtonText;
line-height: normal;
cursor: default;
text-align: center;
text-indent: 0;
text-shadow: none;
}
button:active:hover {
padding: 0px 5px 0px 7px;
border-style: inset;
background-color: ButtonFace;
color: ButtonText;
}
button:disabled:active, button:disabled {
padding: 0px 6px 0px 6px;
border: 2px outset ButtonFace;
color: GrayText;
cursor: inherit;
}