**`<button>`** defaults to **`type="submit"`** when placed inside a `<form>` — meaning a plain `<button>Click</button>` with no explicit type will submit the enclosing form, which surprises many developers. Use `type="button"` for a button that should do nothing on its own except trigger JavaScript (e.g. via `onclick` or `addEventListener`), and `type="reset"` to clear the form back to its default values. Unlike `<input type="submit">`, a `<button>` can contain rich content — icons, nested `<span>`s, images — not just plain text.
1Understanding <button>
`<button>` defaults to `type="submit"` when placed inside a <form> — meaning a plain <button>Click</button> with no explicit type will submit the enclosing form, which surprises many developers. Use type="button" for a button that should do nothing on its own except trigger JavaScript (e.g. via onclick or addEventListener), and type="reset" to clear the form back to its default values. Unlike <input type="submit">, a <button> can contain rich content — icons, nested <span>s, images — not just plain text.
Inside a form, always set an explicit type on every <button> — forgetting it on a button meant for a JS action (like 'Add another item') will accidentally submit the whole form when clicked.
<form>
<input type="text" name="item">
<button type="button" onclick="addItem()">Add Item</button>
<button type="submit">Save All</button>
</form>2Practical Example
Here is a real-world application of <button> showing how it is used in production HTML.
<!-- A button with an icon and text, only possible with <button>, not <input> -->
<button type="submit">
<span class="icon">✓</span> Confirm Order
</button>3Best Practices
Follow these guidelines when working with <button>:
1. Always set an explicit type (submit, reset, or button) on every <button>, never rely on the default
2. Use type="button" for anything driven purely by JavaScript, not form submission
3. Prefer <button> over <input type="submit"> when you need icons or richer content inside it
Tip: Inside a form, always set an explicit type on every <button> — forgetting it on a button meant for a JS action (like 'Add another item') will accidentally submit the whole form when clicked.
<form>
<input type="text" name="item">
<button type="button" onclick="addItem()">Add Item</button>
<button type="submit">Save All</button>
</form>