HTML button Tag formtarget Attribute Tutorial

In this section, we will learn what formtarget attribute is and how it works.

What is formtarget Attribute in HTML <button> Tag?

When we send a form-data to a server, usually, the server responses with some sort of data to signal if the operation was a success or a failure.

So the formtarget attribute is used to declare where this returned response from the server should be displayed! (For example, in a new window or tab, in a specific iframe, or the current document’s window, etc.)

Note: HTML <form> element has an attribute named target which serves the same purpose. But if a form has already this attribute and we use the formtarget attribute in the <button> element as well, the value of formtarget attribute will override the value of the target attribute.

HTML formtarget Attribute in <button> Tag Syntax:

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

<button> Tag formtarget Attribute Values

In the table below, you can see the list of values for the target attribute

Name

Description

_blank

Open the linked document on a new tab or window.

_self

Open the linked document on the window of the current document.

_parent

Open the linked document on the parent frame

_top

Open the linked document on the full body of the window

framename

Open the linked document on the specified iframe.

Example: using formtarget attribute in HTML <button> tag

See the Pen using formtarget attribute in HTML <button> tag by Omid Dehghan (@odchan1) on CodePen.

Leave a Reply