Dofactory.com
Dofactory.com

HTML formtarget Attribute

The formtarget attribute on a submit button tag specifies where to display the form response following submission.

This attribute can be applied to a <button> or <input> element of type submit.

Example

#

A formtarget attribute on the second submit <button> tag.
This button opens a new tab when submitting.

<form action="/tutorial/action.html" target="_self">
  <input type="text" name="name" placeholder="Enter your name">

  <button type="submit">Submit</button>
  <button type="submit" formtarget="_blank">Submit in new tab</button>
</form>

For additional details see our HTML button formtarget Reference.


Using formtarget

The formtarget attribute on the submit button overrides the form's target attribute.

This attribute specifies where to display the response when data is submitted.


Syntax

<tagname type="submit" formtarget="_blank | _self | _parent | _top | framename">

Values

#

Value Description
_self Opens the page in the same tab/window. This is the default.
_blank Opens the page in a new tab.
_parent Opens the page in the parent iframe. In the same iframe if there is no parent.
_top Opens the page in the topmost part of the iframe. In the same iframe if there is no topmost.
framename Opens the page in a named iframe.

Elements that accept formtarget

The following elements accept the formtarget attribute.

Elements Description
<button> Must be a clickable button with type="submit" -- see example above
<input> Must be an input element with type="submit" or type="image".

<input> with formtarget

A formtarget attribute on a submit <input> element.
The second submit button will display the form response in a new tab.


<form action="/tutorial/action.html">
  <input name="email" placeholder="Enter your email"><br/>

  <input type="submit" value="Submit 1"/>
  <input type="submit" value="Submit 2" formtarget="_blank"/>
</form>

For additional details see our HTML input formtarget Reference.


Browser support

Here is when formtarget support started for each browser:

Here is when formtarget support started for each browser:

Chrome
9.0 Sep 2011
Firefox
4.0 Mar 2011
IE/Edge
10.0 Sep 2012
Opera
10.6 Jul 2010
Safari
5.1 Sep 2013

You may also like




Author: Jack Poorte
Published: Jun 20 2021
Last Reviewed: Sep 30 2023


What's your favorite/least favorite part of Dofactory?


Guides