This article is In Progress.
The button element represents a clickable button.
You can put text or images inside a button element. If the element is not disabled, the user can activate the button.
By default, the button element is used to submit form data. Modifying the type attribute can change this behavior.
Attributes (HTML 4)
- The name of the button. This can be used to identify which button was used to submit a form.
- This specifies the type of the button. If omitted, the type is
submit. The following types are possible:
submit: the button submits the form it is associated with and sends the form data to the server. This is the default value.
reset: the button resets the form it is associated with. This will set the containing fields to their initial values.
- The initial value of the button.
- 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, for example fieldset if there is no containing element with the disabled attribute set, then the button is enabled. A disabled button isn’t clickable.
Additional attributes (HTML 5, candidate specification)
- When this attribute is set to "true" the button will have input focused after 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.
- Specifies which form the button is associated with. The value of the attribute must be the id attribute of the form. If this attribute is not specified, the button must be a descendant of the form itself to be able to submit form data. This attribute enables you to place button elements anywhere within a document, not just as descendants of their form elements.
- The URI of a program that processes the information from the form. When present, it will override the action attribute of the associated form.
- The HTTP method to send the form data. This can either be "post" or "get". If specified, it will override the method attribute of the associated form.
Possible values are:
- post: The data from the form is included in the body of the form and is sent to the server.
- get: The data from the form are appended to the form attribute URI, with a '?' as a separator, and the resulting URI is sent to the server. Use this method when the form has no side-effects and contains only ASCII characters.
- If the button is a submit button, this attribute specifies whether the form should be validated or not. It overrides the novalidate attribute of the form it belongs to.
- This attribute is a keyword, indicating where to display the response that is received after submitting the form. This can be one of the following:
_self: load the response into the same context as the form itself. This is the default value.
_blank: load the response into a new, unnamed context (Browser window)
_parent: loads the response into the parent context. If there is no parent, it will behave the same as _self.
_top: loads the response into the top-most context. This is the browsing context of an ancestor of the current context. If there is no parent, it will behave the same as _self.
All these attributes, except
name, have default values and can be omitted.
View live exampleThis examples uses the
<button> element to display a clickable button with out sending or reseting a form.
<button name="myButton" type="button">Click me</button>
<form action="dataReceiverURI"> <label for="name">Name:</label> <input id="name" type="text" name="user_name"> <button name="mySubmitButton">Submit</button> </form>
<form> <label for="name">Name:</label> <input id="name" type="text" name="user_name" > <button name="myResetButton">reset</button> </form>
Generally, the button element can be used whenever there should be a button clickable by the user.
The ending tag is mandatory. The button should have a descriptive text inside it, otherwise the button will be empty and the user won't know what the button will do.
Please note that styling a submit button using the <button> element is easier than styling an input element with type
Since the default for the
type attribute is
submit, the type can be omitted if no other type needs to be used. Historical browser versions may have different standard
|HTML5||W3C Candidate Recommendation|
|WhatWG HTML Living Standard||Living Standard|
|Feature||Chrome||Firefox (Gecko)||Internet Explorer||Opera||Safari|
|Basic Support||Supported (when?)||Supported (when?)||Supported (when?)|| Supported (when?)
|Feature||Android||BlackBerry||Chrome for mobile||Firefox Mobile (Gecko)||IE Mobile||Opera Mobile||Opera Mini||Safari Mobile|
|Basic Support||Supported (when?)||?||Supported (when?)||?||?||?||?||Supported (when?)|
|Internet Explorer||8 and later||The default value of the type attribute depends on the current document compatibility mode. In IE8 Standards mode, the default value is submit. In other compatibility modes and earlier versions of Windows Internet Explorer, the default value is button. When the BUTTON element is submitted in a form, the value depends on the current document compatibility mode. In IE8 mode, the value attribute is submitted. In other document modes and earlier versions of Internet Explorer, the innerText value is submitted.|