👀 Live Preview
Form defaults to target="_blank", but one button overrides to _self:

The formtarget attribute lets developers specify where to display the response after submitting a form. Applied to submit buttons, it overrides the form’s target attribute for that one submission—opening results in the same tab, a new tab, or a named iframe.
Per-button context.
New tab/window.
Same tab default.
Load into iframe.
JS property name.
Form vs button.
formtarget AttributeThe primary purpose of the formtarget attribute is to define the browsing context where the response to a form submission should be displayed. By default, the form’s target attribute (or _self if omitted) controls this behavior.
With formtarget, individual submit buttons can send the response elsewhere—for example, opening a printable receipt in a new tab while keeping the main page unchanged, or loading results into an embedded preview iframe.
The <form> element uses target. Submit controls use formtarget to override it for that button only.
Add formtarget to a submit button with a browsing context name:
<form action="/submit" method="post" target="_blank">
<input type="text" name="query">
<input type="submit" value="Open here" formtarget="_self">
<input type="submit" value="Open new tab" formtarget="_blank">
</form><button type="submit">, <input type="submit">, and <input type="image">.target only for that button’s submission.target attribute: _self, _blank, _parent, _top, or a frame name.formaction, formmethod, and formenctype for full per-button control.The formtarget attribute accepts various values to determine where the form response is displayed. Common values include:
_self — Default behavior. Displays the response in the same window or tab that submitted the form._blank — Opens the response in a new browser window or tab._parent — Targets the parent browsing context of the current frame._top — Targets the top-level browsing context (the full window, breaking out of all frames).framename — A custom name matching an <iframe name="..."> where the response loads.<!-- Same tab -->
<button type="submit" formtarget="_self">Submit</button>
<!-- New tab -->
<button type="submit" formtarget="_blank">Open in new tab</button>
<!-- Named iframe -->
<button type="submit" formtarget="previewFrame">Preview</button>| Value | Behavior | Common Use |
|---|---|---|
_self | Same tab/window | Default navigation |
_blank | New tab/window | Print preview, external result |
_parent | Parent frame | Nested iframe forms |
_top | Top-level window | Break out of frames |
| Frame name | Named iframe | Inline preview panel |
| JS property | button.formTarget | CamelCase in JavaScript |
| Element | Supported? | Notes |
|---|---|---|
<button type="submit"> | Yes | Most common use |
<input type="submit"> | Yes | Classic submit inputs |
<input type="image"> | Yes | Image-based submit control |
<form> | No | Forms use target; buttons use formtarget |
<iframe> | No | iframes receive responses via name + formtarget |
target vs formtarget| Attribute | On | Behavior |
|---|---|---|
target | <form> | Default browsing context for all submit buttons |
formtarget | Submit button / input | Overrides target for that button only |
Override form target on a submit button, open results in a new tab, load into a named iframe, and set formTarget dynamically with JavaScript.
Form defaults to target="_blank", but one button overrides to _self:
Let’s illustrate the usage of the formtarget attribute with an example:
<form action="submit.php" method="post" target="_blank">
<label for="username">Username:</label>
<input type="text" id="username" name="username">
<label for="password">Password:</label>
<input type="password" id="password" name="password">
<input type="submit" value="Submit" formtarget="_parent">
</form>In this example, the form has target="_blank", so the default would open a new tab. The submit button sets formtarget="_parent", instructing the browser to display the response in the parent window instead.
Keep the current page and open the submission response separately:
<form action="/receipt" method="get">
<input type="text" name="orderId" value="12345">
<button type="submit" formtarget="_blank">View receipt in new tab</button>
</form>formtarget="_blank" on the submit button sends the response to a new tab, leaving the original page open—useful for receipts, help docs, or printable views.
The formtarget attribute can be set dynamically on a submit button based on user interaction:
<button type="submit" id="submitBtn">Submit</button>
<script>
document.getElementById("submitBtn").formTarget = "_top";
</script>Setting formTarget = "_top" on the submit button tells the browser to display the response in the top-level browsing context, breaking out of nested frames if the form is embedded.
formtarget="_blank", indicate in button text that a new tab will open.Usually _self unless target is set.
Submit control picks the browsing context.
Same tab, new tab, or named frame.
Flexible navigation without duplicating forms.
The formtarget attribute is supported in all modern browsers. It is part of the HTML5 form submission override attributes.
All major browsers honor formtarget on submit controls.
Bottom line: Use formtarget confidently; test new-tab behavior for accessibility and popup blockers.
target on the formformtarget on the <form> element (use target instead)_blank when same-tab navigation is clearerThe formtarget attribute provides developers with flexibility and control over where form responses are displayed. By understanding how to utilize this attribute effectively on submit buttons, you can enhance the functionality and usability of your web forms.
Pair it with formaction and formmethod when buttons need different URLs and HTTP methods as well. Always prioritize clear labels and predictable navigation for users.
formtargetBookmark these before adding new-tab submit buttons.
Per submit button.
PurposeNew tab/window.
ValueSame tab default.
ValueJS on button.
ScriptUse target there.
Scopetarget for the submit button that was clicked, controlling where the server response is displayed.target on <form>. formtarget belongs on submit buttons and inputs.formtarget="_blank" on the submit button, or target="_blank" on the form for all buttons.target is the form default. formtarget overrides it for one submit button only.submitButton.formTarget = "_blank" or setAttribute("formtarget", "_blank") on the submit control.Practice overriding response targets with formtarget in the Try It editor.
3 people found this page helpful