splitforms.com

HTML · FORM CONTROL

HTML button types: submit, reset and button (live demo)

The <button> element has three types. type="submit" sends the form, type="reset" clears it, and type="button" does nothing until you attach JavaScript. A button with no type acts as submit, which is why a plain button inside a form reloads the page. Set the type on every button.

  • Live, editable example
  • Copy-paste snippet
  • Attributes & common mistakes
Live demo · nothing is sent

What gets submitted

Fill in the form above and press its button. The demo stops the request and lists every name=value pair the browser would send, plus the controls it leaves out.

With a free access key in the form, these fields land in your splitforms dashboard; access_key and botcheck are read by splitforms, not stored as lead data.

Edit the HTML and re-run it
Runs in a sandbox. Nothing is sent.

Minimal snippet

button-example.html
<form action="/contact" method="post">
  <input type="text" name="name">
  <button type="submit">Send</button>   <!-- submits the form -->
  <button type="reset">Clear</button>   <!-- clears the fields -->
  <button type="button">Preview</button> <!-- does nothing without JS -->
</form>

Want this form to email you its submissions? Point it at a free splitforms endpoint, with no server to build. Get a free access key →

Copy-paste code

HTML Button code you can paste today.

Replace YOUR_ACCESS_KEY with a key from your free splitforms dashboard. The form posts to one endpoint — submissions land in your inbox and dashboard with spam filtering built in.

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

  <label for="name">Name</label>
  <input type="text" id="name" name="name" required>

  <label for="email">Email</label>
  <input type="email" id="email" name="email" required>

  <!-- type="submit" is the default inside a form; shown for clarity -->
  <button type="submit">Send message</button>
  <button type="reset">Clear</button>
</form>

Button types

What are the HTML button types?

There are three values for type: submit, reset and button. A missing or misspelled type falls back to submit. Outside a form, submit and reset have nothing to act on, so the button only runs the JavaScript you attach.

What are the HTML button types?
typeInside a formUse it for
submit (the default)Runs validation, then sends the form to its action. Enter in a text field also triggers the form's first submit button.The main action: Send, Sign up, Pay.
resetPuts every field back to its value from the HTML, without asking first.Rarely. People click it by mistake and lose what they typed.
buttonNothing. No submit, no validation, no reload.Script actions: open a dialog, add a row, show a password, preview.
No typeSame as submit.Avoid it: state the type so the button's job is clear.

Sources: WHATWG HTML Standard: the button element · WHATWG HTML Standard: implicit submission · MDN: <button>

Compared

Should I use <button> or <input type="submit">?

Use <button>. Both submit a form the same way, but a <button> can hold icons, <span>s and other inline HTML, and its label is separate from the value it sends. An <input> shows its value as plain text and is a void element with no content.

Should I use <button> or <input type="submit">?
Feature<button type="submit"><input type="submit">
LabelThe content between the tags, HTML allowed.The value attribute, plain text only.
Sent valuename=value from its attributes, only when it is the button that submitted.name=value, where value is also the visible label.
Closing tagRequired: <button>…</button>.None: <input type="submit" value="Send">.
Default typesubmit.Set by type; there is no default to forget.
StylingAny CSS, including flex layouts for an icon and text.Most CSS, but no child elements.

Sources: MDN: <button> · MDN: <input type="submit">

Attributes · <button>

Which attributes does the button element have?

type decides what the button does. The form* attributes change how one submit button sends the form; formaction covers them in depth.

HTML Button attributes and what each one does
AttributeWhat it doesDocs
typesubmit (the default: sends the form), reset (clears all fields) or button (no built-in behaviour, for JavaScript).MDN
nameSent with value only when this button submits the form. Use it to tell several submit buttons apart.MDN
valueThe value sent with the button's name when it triggers the submit. It is not the visible label.MDN
disabledBoolean. Greys the button out, stops clicks and keyboard activation, and leaves it out of the submission.MDN
formThe id of a form elsewhere on the page. Lets a button outside the <form> submit or reset it.MDN
formactionOverrides the form's action for this button only. See [formaction](/html/formaction) for multiple submit buttons.MDN
formmethodOverrides the form's method (get, post or dialog) for this button.MDN
formnovalidateBoolean. Skips required, pattern and the other browser checks when this button submits, for example a Save draft button.MDN
formenctype / formtargetOverride the form's enctype and target for this button.MDN
popovertargetThe id of an element with the popover attribute. The button opens and closes it without JavaScript; use it on type="button".MDN

Common mistakes

HTML Button not working? Here's why.

Most broken forms come down to a few small mistakes with the <button>. Check these before you ship, then forward every submission to Slack or a webhook.

  1. Default type is submit

    A <button> with no type inside a form submits the form. If it should only run JavaScript, set type="button" explicitly or it will reload the page.

  2. Content goes between the tags

    Unlike <input type="submit" value="Send">, a <button> can contain HTML, icons and styled text. Put the visible label inside the button; value= is what gets sent, not what people see.

  3. A button's name and value are sent only when it submits

    With two submit buttons, only the one that was clicked adds its name=value pair. Pressing Enter in a text field submits through the form's first submit button, so put the main action first in the markup.

  4. Don't use a link for an action, or a button for navigation

    A <button> does something on this page: submits, opens, toggles. An <a href> goes to another URL. Screen readers announce them differently, and only buttons respond to the Space key.

  5. A disabled submit button hides the reason

    disabled takes the button out of the Tab order and gives no hint why it can't be pressed. Keep the submit button enabled and let validation say what is missing; disable it only while a submit is in progress.

Sources: WHATWG HTML Standard: <button> · MDN: <button>

name + value

How do I tell which submit button was clicked?

Give the buttons the same name and different values. Only the clicked button is sent, so the backend receives intent=send or intent=draft. formnovalidate on the draft button lets people save an unfinished form. On splitforms, the pair arrives as an ordinary field in the email, dashboard and webhook.

two-submit-buttons.html
<form action="https://splitforms.com/api/submit" method="POST">
  <input type="hidden" name="access_key" value="YOUR_ACCESS_KEY">
  <textarea name="message" required></textarea>

  <button type="submit" name="intent" value="send">Send</button>
  <button type="submit" name="intent" value="draft" formnovalidate>Save draft</button>
</form>

submit event

How do I stop a button from submitting twice?

Disable the button inside the form's submit event, not the button's click event. submit only fires after validation passes, so a click on an invalid form doesn't leave the button stuck. event.submitter is the button that was used.

If you send with fetch, enable the button again when the request fails so people can retry.

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

<script>
  document.getElementById("contact").addEventListener("submit", (event) => {
    const button = event.submitter;
    button.disabled = true;
    button.textContent = "Sending…";
  });
</script>

form attribute

How do I put a submit button outside the form?

Give the form an id and the button a matching form attribute. The button then submits and validates that form from anywhere on the page, such as a sticky footer or a dialog. Without the attribute, a button outside the <form> does nothing.

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

<footer class="sticky-actions">
  <button type="submit" form="signup">Create account</button>
</footer>

Key benefits

Copy-paste ready

The HTML Button example below is a complete, working form — paste it into any HTML page and it submits, no edits to the markup required.

No backend to build

Your html button form posts to one endpoint. No server, PHP, or API route — accepted submissions are saved to your dashboard before owner notification email is attempted; delivery time and inbox placement depend on provider and recipient settings.

A form that really submits

Unlike a static reference snippet, this <button> form actually sends data to a free splitforms backend, with spam filtering built in.

How it works

How to add HTML Button to any page.

Copy the html button example, drop in your free access key, and paste it into any page — submissions start landing in your dashboard.

  1. Copy the code

    Copy the HTML Button example below.

  2. Add your access key

    Replace YOUR_ACCESS_KEY with a free splitforms key from the dashboard.

  3. Paste into your site

    Drop the form into any HTML page. Submissions arrive in your dashboard.

Questions

HTML Button questions, answered.

Anything missing? Email us, we read every message.

A person reading answers to common questions
What are the HTML button types?

There are three: type="submit" (the default, which sends the form), type="reset" (clears all the form's fields), and type="button" (a plain clickable button with no built-in behaviour, used for JavaScript).

What is the default type of an HTML button?

submit. A <button> with no type attribute, or with an invalid one, behaves as type="submit". Inside a form it sends the form when clicked; outside a form it has nothing to submit and does nothing.

What is the button tag in HTML?

The <button> element is a clickable control. Inside a form it can submit or reset the form depending on its type= attribute; outside a form it's a general-purpose button you hook up with JavaScript.

How do I make a submit button in HTML?

Use <button type="submit">Send</button> inside a <form>. The button submits the form to its action URL. (type="submit" is the default inside a form, but stating it is clearer.)

What is the difference between <button> and <input type="submit">?

Both can submit a form. A <button> can contain rich HTML (icons, styled text) between its tags, while an <input> only shows its value= as plain text. Use <button> for anything styled.

Why does my button reload the page?

Because its type defaults to submit inside a form, so it submits and the page navigates. Add type="button" if you only want it to run a JavaScript handler.

Show 2 more questions
How do I run JavaScript when a button is clicked?

Use type="button" and attach a listener: button.addEventListener("click", handler). To act on a form submit instead, listen for the form's submit event, which also fires when someone presses Enter.

Is the button value sent with the form?

Only when that button submitted the form, and only if it has a name. The browser then adds name=value to the data. Other buttons in the form, and buttons without a name, send nothing.

View all FAQs

Make this form actually submit.

Point your form at splitforms. 500 free submissions a month, spam filtering, webhooks on paid plans — no server.

  • No credit card required
  • 500 free submissions
  • Setup in minutes
Two people celebrating a working contact form