The type attribute on a <button> tag specifies the type of button to create.
Options are: button
, submit
, and reset
.
When clicked, each button type has its own behavior.
A type attribute on a <button>.
The attribute specifies the button is a submit button.
<form action="/tutorial/action.html">
<input type="text" name="email" placeholder="Enter your email">
<button type="submit">Submit</button>
</form>
The type attribute specifies the button type and associated behavior.
If this attribute is not set, most browsers will treat a button as a submit button.
For this reason, always specify the type on a button element.
<button type="button | submit | reset">
Value | Description |
---|---|
button | A clickable button. Useful for executing custom client or server-side code. |
submit | A submit button that sends form-data to the server. |
reset | A button that clears all input controls in a form to their original values. |
This form has two button types:
<form action="/tutorial/action.html">
<input type="text" name="email" placeholder="Enter your email">
<button type="submit">Submit</button>
<button type="reset">Reset</button>
</form>
Here is when type support started for each browser:
Chrome
|
1.0 | Sep 2008 |
Firefox
|
1.0 | Sep 2002 |
IE/Edge
|
1.0 | Aug 1995 |
Opera
|
1.0 | Jan 2006 |
Safari
|
1.0 | Jan 2003 |
Back to <button>