HTML Button


Example

<input type="button" value="Button Text">

Buttons can be used for triggering actions to occur on the page, without submitting the form. You can also use the <button> element if you require a button that can be more easily styled or contain other elements:

<button type="button">Button Text</button>

Buttons are typically used with an "onclick" event:

<input type="button" onclick="alert('hello world!')" value="Click Me">

or

<button type="button" onclick="alert('hello world!')">Click Me</button>

Attributes

[name]

The name of the button, which is submitted with the form data.

[type]

The type of the button.

Possible values are:

submit : The button submits the form data to the server. This is the default if the attribute is not specified, or if the attribute is dynamically changed to an empty or invalid value.

reset : The button resets all the controls to their initial values.

button : The button has no default behavior. It can have client-side scripts associated with the element's events, which are triggered when the events occur.

menu : The button opens a popup menu defined via its designated element.

[value]

The initial value of the button.

5

Extra Attributes for Submit Buttons

AttributeDescription
formSpecifies the ID of the form the button belongs to.
If none is specified, it will belong to its ancestor form element (if one exists).
formactionSpecifies where to send the form-data
when the form is submitted using this button.
formenctypeSpecifies how the form-data should be encoded
when submitting it to the server using this button.
Can only be used with formmethod="post".
formmethodSpecifies the HTTP method to use (POST or GET)
when sending form-data using this button.
formnovalidateSpecifies that the form-data should not be validated on submission.
formtargetSpecifies where to display the response that is received
after submitting the form using this button.