HTML formtarget Attribute

The HTML formtarget attribute specifies where the response from a form submission should be displayed when a particular submit button is activated. It overrides the target attribute of the button's associated <form> element for that submission.

Syntax

The formtarget attribute is placed on a submit button and specifies the browsing context where the response should be displayed.

<button type="submit" formtarget="_blank">Submit in New Tab</button>

It can also be used with an <input> element that acts as a submit button.

<input type="submit" value="Submit in New Tab" formtarget="_blank">

Elements That Use the formtarget Attribute

The formtarget attribute applies to elements that act as submit buttons.

Element Description
<button> Specifies an alternate target when the element acts as a submit button.
<input type="submit"> Specifies an alternate target for a submit input.
<input type="image"> Specifies an alternate target for an image submit button.

Attribute Values

The formtarget attribute can use a browsing context name or one of the standard target keywords.

Value Description
_self Displays the response in the current browsing context.
_blank Displays the response in a new top-level browsing context, usually a new tab.
_parent Displays the response in the parent browsing context. If there is no parent, it behaves like _self.
_top Displays the response in the top-level browsing context. If there are no nested contexts, it behaves like _self.
_unfencedTop Allows a form submitted from within a fenced frame to target the top-level browsing context.
name Displays the response in the browsing context with the specified name.

Overriding the Form target

A form normally displays its response according to its target attribute. When the activated submit button has a formtarget attribute, the button's target is used instead.

<form action="result.php" method="post" target="_self">
  <input type="text" name="message">
  <button type="submit">Submit Here</button>
  <button type="submit" formtarget="_blank">Submit in New Tab</button>
</form>

The first button displays the response in the current browsing context. The second button overrides the form's target and displays the response in a new browsing context.

Named Browsing Context

A custom name can be used as the value of formtarget. If a browsing context with that name already exists, the response can be displayed there. Otherwise, the browser can create a new browsing context with that name.

<button type="submit" formtarget="form-result">Show Result</button>

<iframe name="form-result" title="Form Result"></iframe>

In this example, the form response is displayed inside the named <iframe> rather than replacing the current page.

The formtarget attribute belongs to a group of submit-button attributes that can override submission settings defined by the associated form.

Submit Button Attribute Form Attribute Overridden
formaction action
formenctype enctype
formmethod method
formnovalidate novalidate
formtarget target

Common Mistakes

Do not confuse formtarget with the form's target attribute. The target attribute establishes the form's normal target, while formtarget overrides it for an individual submit button.

Do not use formtarget on ordinary controls that cannot submit a form. For <input>, it applies to the submit and image states.

Remember that opening a response with _blank creates a separate browsing context, so users may remain on the original form page while the response appears elsewhere.

Browser Support

Baseline: Widely available indicates a feature has been supported by core browsers for at least 30 months. At this stage, the feature is considered stable and safe for most websites to use without needing to worry about compatibility issues or fallbacks, as it is supported by the vast majority of users' devices and browser versions.

The formtarget attribute is widely supported on submit-capable <button> and <input> elements in current core browsers.

Checking Browser Support

For current browser compatibility information, visit Can I Use? . Search for the HTML element or attribute you want to check. You can also narrow your search by entering an element name and attribute name separated by a colon. Search results can include related HTML features, element attributes, input types, APIs, and other technologies, so select the result that most closely matches the feature you are checking.

Try the formtarget Attribute

The example uses two submit buttons. The first displays the form response in the editor window, while the second uses formtarget="_blank" to display the response in a new tab or window.

Play in Editor

Summary

The HTML formtarget attribute specifies where the response from a form submission should be displayed when a particular submit button is used. It overrides the associated form's target attribute and can use standard target keywords such as _self, _blank, _parent, and _top, or the name of a browsing context.