CSS Portal

HTML formtarget Attribute

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
formtarget
HTML AttributeThis attribute is supported by all modern browsers.
Updated 29th March 2024

Description

The formtarget attribute is an HTML attribute that specifies the name or keyword of a browsing context (such as a tab, window, or iframe) where the results of submitting a form should be displayed. This attribute is used in conjunction with form elements like <input> and <button>, particularly when those elements are of type "submit".

The formtarget attribute overrides the target attribute of the form with which the submit button or input is associated. This provides flexibility, allowing different submit buttons in the same form to target different results to different locations, such as different iframes or new windows.

The attribute can take several values:

  • The name of a frame or iframe.
  • Special keywords such as _self (the current browsing context), _blank (a new unnamed window or tab), _parent (the parent of the current context), and _top (the topmost browsing context).

If no formtarget is specified, the form is submitted to the current window or iframe, unless otherwise specified by a target attribute on the form itself. This attribute is useful for controlling the user experience by directing form results to appropriate locations, making it easier to design complex web applications that require forms to interact with various parts of the user interface.

Syntax

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

Values

  • _blankOpens the page in a new tab.
  • _selfOpens the page in the same tab/window. This is the default.
  • _parentOpens the page in the parent iframe. In the same iframe if there is no parent.
  • _topOpens the page in the topmost part of the iframe. In the same iframe if there is no topmost.
  • framenameOpens the page in a named iframe.

Applies To

Example

<form action="formscript.php" method="post">
Name:<br><input type="text" name="name"><br><br>
Email:<br><input type="email" name="email"><br><br>
<input type="submit" value="Submit (New Window)" formtarget="_blank">
<input type="submit" value="Submit (Same Window)" formtarget="_self">
</form>
Open in editor

Browser Support

The following information will show you the current browser support for the HTML formtarget attribute. Hover over a browser icon to see the version that first introduced support for this HTML attribute.

This attribute is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee