splitforms.com
guide · html elements

HTML Button — Types, Attributes, and Common Patterns

An HTML button is `<button>` (preferred) or `<input type="button">` (legacy). The `type` attribute determines what it does inside a form — submit (default), reset, or button (no default action). Complete reference plus working code.

html
<!-- Standard form submit button -->
<form action="https://splitforms.com/api/submit" method="POST">
  <input type="hidden" name="access_key" value="YOUR_ACCESS_KEY" />
  <input name="email" type="email" required />

  <!-- type="submit" is the default for buttons inside a form -->
  <button type="submit">Send</button>
</form>

<!-- Button that doesn't submit a form (for JS handlers) -->
<button type="button" onclick="alert('Clicked!')">
  Click me
</button>

<!-- Button with custom action via formaction (HTML5) -->
<form action="/api/save" method="POST">
  <input name="content" />
  <button type="submit">Save</button>
  <button type="submit" formaction="/api/publish">Publish</button>
</form>

<!-- Disabled button -->
<button type="submit" disabled>Sending…</button>

Use `<button>` over `<input type="submit">`. Same functional behavior, but `<button>` can contain rich HTML (icons, spans for styling, accessible labels) while `<input>` is restricted to a `value` attribute. Modern conventions universally prefer the `<button>` element.

The `type` attribute decides the button's behavior inside a form. `type="submit"` (the default) triggers form submission. `type="reset"` clears all form fields back to their initial values. `type="button"` does nothing by default — use it when you want a JavaScript-only action without triggering submit.

The default type for a button inside a form is `submit`. This trips up developers: a button that says 'Show more' that's inside a form, without `type="button"`, will accidentally submit the form when clicked. Always set `type="button"` explicitly for non-submit buttons.

HTML5 added the `formaction`, `formenctype`, `formmethod`, `formnovalidate`, and `formtarget` attributes that let an individual submit button override the form's corresponding attributes. Useful for forms with multiple submit destinations (Save Draft vs Publish), or a 'Save without validation' option.

How to set this up

Step 01

Use <button>, not <input type="submit">

Same submission behavior, but <button> can contain rich HTML for icons, loading spinners, etc.

Step 02

Set type explicitly

type="submit" for submit buttons, type="button" for JS-only buttons. Never omit on buttons that aren't supposed to submit.

Step 03

Disable during async submission

Set the disabled attribute on submit to prevent double-clicks. Re-enable on response or error.

Step 04

(Optional) Use formaction for multi-action forms

Per-button override of the form's action URL. Cleaner than separate forms with hidden inputs.

<button> over <input>. Set type explicitly. Disable during async submit.

Frequently asked questions

What is a button in HTML?

An HTML button is the <button> element — a clickable control that the user can press to trigger an action. Inside a form, the default action is to submit the form; outside a form, it requires a JavaScript onclick handler.

What's the difference between button and input type=submit?

Functionally equivalent for form submission. <button> can contain HTML (icons, formatted text); <input type="submit"> is restricted to a text value attribute. Modern code uses <button>.

What are the types of HTML button?

Three: submit (default in forms — triggers submission), reset (clears form fields), button (no default action, requires JS onclick).

How do I disable a button in HTML?

Add the disabled attribute: <button disabled>. The button can't be clicked or focused while disabled. Use this during async submission to prevent double-clicks.

How do I style an HTML button?

Plain CSS — target the <button> element directly or via a class. Reset the browser default styling (background, border, padding) and apply your own. <button> respects every standard CSS property.

What does the formaction attribute do?

formaction on a <button type="submit"> overrides the form's action attribute when that specific button is clicked. Useful for forms with multiple submit destinations — e.g., Save Draft vs Publish posting to different endpoints.

Related guides

HTML forms

HTML Form — How to Build and Submit Forms in HTML

HTML forms

HTML Form Action — What It Does and How to Use It

HTML elements

HTML Radio Button — Working Code and Common Patterns

HTML elements

HTML Textarea — Multi-Line Text Input Reference

Ship the form, not the backend.

Free for 1,000 submissions/month. Email delivery, AI spam filtering, signed webhooks, real dashboard — all on the free plan. No credit card.

Get a free access key →