HTML formtarget Attribute

Beginner
⏱️ 5 min read
📚 Updated: Jun 2026
🎯 3 Examples
Forms & Navigation

What You’ll Learn

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.

01

Override target

Per-button context.

02

_blank

New tab/window.

03

_self

Same tab default.

04

Frame name

Load into iframe.

05

formTarget

JS property name.

06

vs target

Form vs button.

Purpose of formtarget Attribute

The 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.

💡
On submit buttons, not on <form>

The <form> element uses target. Submit controls use formtarget to override it for that button only.

📝 Syntax

Add formtarget to a submit button with a browsing context name:

formtarget.html
<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>

Syntax Rules

  • Valid on submit controls: <button type="submit">, <input type="submit">, and <input type="image">.
  • Overrides the parent form’s target only for that button’s submission.
  • Values mirror the form target attribute: _self, _blank, _parent, _top, or a frame name.
  • Works with formaction, formmethod, and formenctype for full per-button control.

💎 Values

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.
formtarget-values.html
<!-- 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>

⚡ Quick Reference

ValueBehaviorCommon Use
_selfSame tab/windowDefault navigation
_blankNew tab/windowPrint preview, external result
_parentParent frameNested iframe forms
_topTop-level windowBreak out of frames
Frame nameNamed iframeInline preview panel
JS propertybutton.formTargetCamelCase in JavaScript

Applicable Elements

ElementSupported?Notes
<button type="submit">YesMost common use
<input type="submit">YesClassic submit inputs
<input type="image">YesImage-based submit control
<form>NoForms use target; buttons use formtarget
<iframe>Noiframes receive responses via name + formtarget

Form target vs formtarget

AttributeOnBehavior
target<form>Default browsing context for all submit buttons
formtargetSubmit button / inputOverrides target for that button only

Examples Gallery

Override form target on a submit button, open results in a new tab, load into a named iframe, and set formTarget dynamically with JavaScript.

👀 Live Preview

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

Implementation Example — Override Form Target

Let’s illustrate the usage of the formtarget attribute with an example:

index.html
<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>
Try It Yourself

How It Works

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.

Example — Open Result in New Tab

Keep the current page and open the submission response separately:

new-tab.html
<form action="/receipt" method="get">
  <input type="text" name="orderId" value="12345">
  <button type="submit" formtarget="_blank">View receipt in new tab</button>
</form>
Try It Yourself

How It Works

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.

Dynamic Values with JavaScript

The formtarget attribute can be set dynamically on a submit button based on user interaction:

index.html
<button type="submit" id="submitBtn">Submit</button>

<script>
  document.getElementById("submitBtn").formTarget = "_top";
</script>
Try It Yourself

How It Works

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.

♿ Accessibility

  • Warn when opening new tabs — If formtarget="_blank", indicate in button text that a new tab will open.
  • Avoid unexpected navigation — Users should understand whether they stay on the page or leave it.
  • Do not trap focus — New windows should be keyboard-accessible and closable.
  • Label iframe targets clearly — When loading into a preview frame, provide a heading or label for that region.

🧠 How formtarget Works

1

Form sets default target

Usually _self unless target is set.

Markup
2

Button may override with formtarget

Submit control picks the browsing context.

Override
3

Browser loads response

Same tab, new tab, or named frame.

Navigate
=

Control where users land

Flexible navigation without duplicating forms.

Browser Support

The formtarget attribute is supported in all modern browsers. It is part of the HTML5 form submission override attributes.

HTML5 · Fully supported

Universal target override

All major browsers honor formtarget on submit controls.

99% Browser support
Google Chrome Fully supported
Full support
Mozilla Firefox Fully supported
Full support
Apple Safari Fully supported
Full support
Microsoft Edge Fully supported
Full support
formtarget attribute 99% supported

Bottom line: Use formtarget confidently; test new-tab behavior for accessibility and popup blockers.

💡 Best Practices

✅ Do

  • Consider user experience when choosing submission targets
  • Tell users when a button opens a new tab
  • Use named iframe targets for inline previews
  • Test across browsers and devices
  • Keep a sensible default target on the form

❌ Don’t

  • Put formtarget on the <form> element (use target instead)
  • Open new tabs without warning users
  • Rely on frames for critical flows without fallbacks
  • Overuse _blank when same-tab navigation is clearer
  • Forget that popup blockers may affect some target behavior

Conclusion

The 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.

Key Takeaways

Knowledge Unlocked

Five truths every developer should know about formtarget

Bookmark these before adding new-tab submit buttons.

5
Core concepts
📄 02

_blank

New tab/window.

Value
👆 03

_self

Same tab default.

Value
⚙️ 04

formTarget

JS on button.

Script
📋 05

Not on form

Use target there.

Scope

❓ Frequently Asked Questions

It overrides the form’s target for the submit button that was clicked, controlling where the server response is displayed.
No. Use target on <form>. formtarget belongs on submit buttons and inputs.
Set 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.
Use submitButton.formTarget = "_blank" or setAttribute("formtarget", "_blank") on the submit control.
Yes in all modern browsers. IE 10+ also supports formtarget on submit controls.

Control where forms navigate

Practice overriding response targets with formtarget in the Try It editor.

Try target override example →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

3 people found this page helpful