formtarget

The formtarget attribute determines the browsing context (such as a tab, window, or iframe) where the results of a form submission will be displayed.

formtarget attribute

The formtarget attribute in HTML indicates the name or keyword of a browsing context (like a tab, window, or iframe) where the form submission results will be shown. It is used with form elements such as <input> and <button>, especially those of type "submit".

Syntax

index.html
<input formtarget="_blank|_self|_parent|_top|framename">

Example

Here’s an example of how the formtarget attribute works:

index.html
<form method="post">
  <input type="text" name="username" placeholder="Username">
  <input type="submit" value="Submit" formtarget="_blank">
</form>
The formtarget attribute can be used with elements of type="submit" and type="image".

Values

  • _blank: Opens the submission results in a new tab.
  • _self: Displays the results in the same tab/window (default).
  • _parent: Opens the results in the parent iframe, or in the current iframe if no parent exists.
  • _top: Displays the results in the topmost frame, or in the same iframe if no topmost frame is present.
  • framename: Opens the results in a specific named iframe.

Applies To

The formtarget attribute can be used with the following HTML elements.

Example

Name:


Email:


index.html
<form 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>

Conclusion

The formtarget attribute specifies where the form submission results will appear, such as in a new tab, the current window, or within an iframe. It can be used with <input> and <button> elements. Key values include _blank, _self, _parent, and _top to define the target browsing context.