How to Stop a Button from Submitting a Form in HTML
Every <button> inside a <form> sends the form when it's clicked, unless you say otherwise. Add type="button" and it becomes a plain button that leaves the form alone, ready for a script to give it a job.
Syntax
<button type="button"><text></button>
| Part | What it does |
|---|---|
type="button" | Makes it a plain button: clicking it doesn't send the form. A script can still listen for its clicks. |
<text> | The text on the button. |
Without type, a button in a form is a submit button: Chromium reported submit as the type of a button that has no type attribute. MDN's button page lists the three types, submit, reset and button, and confirms that submit is the default.
The Example
The example form has a text box and two buttons: Check spelling, with type="button", and Send, which sends the form. You click Check spelling and the text stays. Then you take the type away and click it again, to see what changes.
Step 1: Write the Code
Create a file named index.html in a text editor, such as Visual Studio Code:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Button types</title>
</head>
<body>
<form>
<label for="name">Name</label>
<input id="name" name="name">
<button type="button">Check spelling</button>
<button type="submit">Send</button>
</form>
</body>
</html>
Step 2: Type a Name and Click Check spelling
Double-click index.html to open it in your browser. Type Ana and click Check spelling:

Nothing happens, and that's the point: the text box still says Ana, and the address still ends with index.html. In a real page, a script would check the spelling here.
Step 3: Take the type Away and Try Again
In index.html, change <button type="button">Check spelling</button> to <button>Check spelling</button> and save the file. Reload the page, type Ana again and click Check spelling:

This time the button sent the form: the page loaded again with an empty text box, and the address ended with ?name=Ana. The screenshots come from Chromium 159, the open-source browser that Chrome is built on.
What Happened
type="button"made Check spelling a plain button, so clicking it left the form alone.- Without
type, it was a submit button, the default for a button in a form. Chromium reported the type of both buttons assubmit, so either one sent the form. - Sending the form loaded the page again, which is why the text box was empty.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Leaving out type on a button that shouldn't send the form | Clicking it sends the form and loads the page again, so what people typed is gone | Add type="button" |
Writing type="button" on the button that should send the form | Clicking it sends nothing | Use type="submit" for the send button |
Using type="reset" for a Clear button that people may click by accident | A test showed it puts every field back to its starting value without asking | Leave it out, or make sure people can't mistake it for Send |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| The page reloads when a button is clicked | The button has no type, so it's a submit button | Add type="button" |
| The form isn't sent | The send button has type="button" | Change it to type="submit" |
?name=... appears in the address after a click | A button without a type sent the form | Add type="button" to that button |
FAQ
Can a script still react to a type="button" button?
Yes. type="button" only stops it from sending the form: a click listener added to the button runs as usual.
What does type="reset" do?
It puts every field in the form back to its starting value. In a test, a text box that started with Ana was changed to Ben, and clicking a type="reset" button brought back Ana, without sending the form.
Does a button outside a form need a type?
A button that isn't in a form has no form to send: in a test, clicking one without a type left the page and the text box just as they were. Adding type="button" anyway is a good habit, in case the button ends up inside a form later.
Conclusion
A button in a form sends the form unless it has type="button". Give every button its type, submit for the one that sends and button for the rest, and no click sends the form by surprise.
Additional Resources
- button: The Button element, on MDN.
