HTML formtarget Attribute

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

The formtarget attribute can be used on the following html elements.

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>

Browser Support

The following table will show you the current browser support for the HTML formtarget Attribute.

Desktop
Edge Chrome Firefox Opera Safari
YesYesYesYesYes
Tablets / Mobile
Chrome Firefox Opera Safari Samsung Webview
YesYesYesYesYesYes

Last updated by CSSPortal on: 29th March 2024