splitforms.com

HTML · FORM ATTRIBUTE

HTML form target attribute

The target attribute on a <form> names the browsing context that shows the response after submit. The default is _self, the same tab. _blank opens a new tab. A name that matches an <iframe name> loads the response in that iframe, so the visitor stays on the page. formtarget on a button overrides it for that one 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

form-target-example.html
<form action="/subscribe" method="post" target="_blank">
  <button type="submit">Subscribe</button>
</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 Form target 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.

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

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

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

  <!-- Honeypot: hidden from people, bots fill it in -->
  <input type="checkbox" name="botcheck" style="display:none" tabindex="-1" autocomplete="off">

  <button type="submit">Send</button>
</form>

<!-- The response loads here, so this page doesn't redirect -->
<iframe name="sf-result" title="Form result" hidden></iframe>

Attributes · <form target>

Which HTML Form target attributes matter?

These attributes decide how the <form target> behaves and what actually gets emailed to your inbox when someone submits.

HTML Form target attributes and what each one does
AttributeWhat it does
_selfThe default. The response replaces the current page in the same tab.
_blankOpens the response in a new tab or window. The form page stays open in the old tab.
_parentLoads the response in the parent frame. With no parent it acts like _self.
_topLoads the response in the top-level tab, replacing every frame. Useful when the form sits inside an iframe.
a named iframeAny other name, like target="sf-result", loads the response in the <iframe name="sf-result">. If no such frame exists, the browser opens a new tab.
formtargetSet on a <button> or <input type="submit">. Overrides the form's target for that button only.

Common mistakes

HTML Form target not working? Here's why.

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

  1. Popup blockers can stop _blank

    When a script calls form.submit() without a click from the visitor, some browsers treat a target="_blank" submission as a popup and block it. Let a real submit button send the form.

  2. The iframe needs a name, not an id

    target matches the iframe's name attribute. <iframe id="sf-result"> won't work, and the response opens in a new tab instead.

  3. You can't read a cross-origin iframe

    When the response comes from another domain, your JavaScript can't read what loaded in the iframe. To show a confirmation, use the endpoint's redirect or send the form with fetch() and read the JSON response.

  4. target is ignored with fetch()

    When you send the form with fetch(), no page loads anywhere, so target has no effect. Your script decides what to show.

Sources: WHATWG HTML Standard: target · MDN: the form element, target

Key benefits

Copy-paste ready

The HTML Form target 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 form target 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 <form target> form actually sends data to a free splitforms backend, with spam filtering built in.

How it works

How to add HTML Form target to any page.

Copy the html form target 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 Form target 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 Form target questions, answered.

Anything missing? Email us, we read every message.

A person reading answers to common questions
How do I open form results in a new tab?

Add target="_blank" to the <form>. When the visitor clicks submit, the response opens in a new tab and the form page stays open in the original one.

How do I submit a form without leaving the page?

Add an <iframe name="result" hidden> to the page and set target="result" on the form. The response loads in the hidden iframe, so the page doesn't redirect. You can also send the form with fetch() instead.

What is formtarget?

formtarget goes on a submit button and overrides the form's target for submissions made with that button only. For example, one button can open a preview in a new tab while another submits in the same tab.

Does target change what data is sent?

No. target only decides where the response is shown. The fields, the method and the encoding are exactly the same whatever target you use.

What is the default target of a form?

_self. With no target attribute, the response replaces the current page in the same tab, unless a <base target> on the page sets a different default.

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