Sobes.tech
Junior

What is the target attribute, what values does it take, and what function does it perform?

sobes.tech AI

Answer from AI

The target attribute of the HTML <a> element specifies where the linked page will be displayed.

It accepts the following values:

  • _self: Opens the link in the current window/frame (default value).
  • _blank: Opens the link in a new window or tab.
  • _parent: Opens the document in the parent frame of the current frame. If there are no frames, it works like _self.
  • _top: Opens the document in the full window, canceling all frames. If there are no frames, it works like _self.
  • iframe_name: Opens the document in a frame with the specified name.

Example usage:

<a href="https://example.com" target="_blank">Open in a new tab</a>
<a href="https://another.com" target="_self">Open in the current tab</a>

The function of the target attribute is to control the browser's behavior when following a link, allowing to open new windows, tabs, or manage content display within frames on the current page.