SyntaxStudy
Sign Up
HTML Beginner 6 min read

Link Targets

Link Targets

The target attribute of the <a> element controls where the linked document opens. The most common values are _self (default — same tab) and _blank (new tab or window).

Security with target="_blank"

When you open a link in a new tab with target="_blank", the new page can access the opening page via window.opener. Always add rel="noopener noreferrer" to prevent this security vulnerability. noopener blocks access to window.opener and noreferrer additionally hides the referrer header.

  • target="_self" — Same browsing context (default)
  • target="_blank" — New tab / window
  • target="_parent" — Parent frame
  • target="_top" — Full window body
Example
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Link Targets</title>
</head>
<body>
  <h1>Link Targets</h1>

  <!-- Opens in same tab (default) -->
  <p><a href="page2.html">Same Tab</a></p>

  <!-- Opens in new tab, safe version -->
  <p>
    <a href="https://example.com"
       target="_blank"
       rel="noopener noreferrer">
      External Site (new tab)
    </a>
  </p>

  <!-- Inside an iframe, targets the parent -->
  <p><a href="home.html" target="_parent">Home</a></p>
</body>
</html>
Pro Tip

Only open links in a new tab (target="_blank") when it genuinely benefits the user, such as when leaving the current page would interrupt a workflow — do not do it by default, as it takes away browser navigation control from the user.