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.
Example
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
Tablets & Mobile
Last updated by CSSPortal on: 29th March 2024
