References

Beginner-friendly references for web development, with live, editable examples.

The HTML type attribute

Attribute All modern browsers Updated
Quick answer

The HTML type attribute sets what the button does when activated. It is used on the <button> element.

Overview

The type attribute sets what the button does when activated. It applies to the <button> element.

Always set it explicitly: a <button> inside a form defaults to submit, which often causes accidental submissions. Use type="button" for buttons that run JavaScript.

Syntax

<button type="button">Click</button>

Values

Value
submit (default in a form) | reset | button

Example

Live example
<button type="button" onclick="this.textContent='Clicked'">Click me</button>

Best practices

  • Always set an explicit type on a <button> — the default inside a form is submit.
  • Use the form* override attributes only when one button genuinely needs different submission behavior.
  • Give every button clear, descriptive text for screen readers.
  • Prefer real <button> elements over clickable <div>s for keyboard and accessibility support.

Frequently asked questions

What does the type attribute do?
Sets a button's behavior.
Why does my button submit the form unexpectedly?
A <button> inside a form defaults to type="submit". Add type="button" if it should not submit.
Can one button submit to a different URL than the form?
Yes. Put formaction (and optionally formmethod) on that submit button to override the form.
Which elements use the type attribute?
It is an element-specific attribute, used on <button> and submit-type <input> controls.