👀 Live Preview
Two links with different target behavior:

In HTML, the target attribute is used with hyperlinks to specify where the linked document should be displayed. By default, clicking a link opens the destination in the same browser tab. With target, you can open links in a new tab, a named iframe, or (in legacy frame layouts) a specific frame.
The most common value is _blank, which opens a link in a new tab or window. Always pair external _blank links with rel="noopener noreferrer" for security.
New tab.
Same tab.
iframe target.
Security.
link.target.
New tab hints.
targetThe primary purpose of the target attribute is to define the browsing context for the linked document. It gives developers flexibility in how users interact with linked content—keeping users on your page while they view external resources, or loading content into a specific iframe.
Use it thoughtfully: opening many links in new tabs can disorient users. Reserve _blank for cases where losing the current page would be harmful (such as mid-form workflows or PDF downloads).
Always add rel="noopener noreferrer" on external links with target="_blank". Without noopener, the new page can access window.opener and potentially redirect your original tab (tabnabbing).
Add target to an anchor with an href:
<a
href="https://www.example.com"
target="_blank"
rel="noopener noreferrer">
Visit Example.com
</a><a href="...">.<form> (see formtarget for submit buttons), <area>, and <base>._blank, _self, _parent, _top) or a custom frame/window name._self (same tab).name on <iframe> or window.open.HTMLAnchorElement.target.The target attribute accepts keyword values and custom frame names:
_blank — Opens the linked document in a new, unnamed browsing context (usually a new tab)._self (default) — Opens in the same browsing context (same tab or frame)._parent — Opens in the parent frame. If there is no parent, behaves like _self._top — Opens in the top-level browsing context, breaking out of nested frames.myFrame) — Opens in a frame, iframe, or window with that name._blank<a href="https://www.example.com" target="_blank" rel="noopener noreferrer">Visit Example.com</a>_self<a href="https://www.example.com" target="_self">Visit Example.com</a>_parent and _top<a href="https://www.example.com" target="_parent">Parent frame</a>
<a href="https://www.example.com" target="_top">Top window</a><a href="page.html" target="myFrame">Load in iframe</a>
<iframe name="myFrame" title="Content panel"></iframe>| Value | Opens in | Common use |
|---|---|---|
_blank | New tab/window | External links |
_self | Same tab (default) | Normal navigation |
_parent | Parent frame | Legacy framesets |
_top | Full window | Break out of frames |
frameName | Named iframe | Split layouts |
With _blank | rel="noopener noreferrer" | Security best practice |
| Element | Supported? | Notes |
|---|---|---|
<a href> | Yes | Most common usage |
<form> | Yes | Where form submission opens |
<area> | Yes | Image map links |
<base> | Yes | Default target for all links on page |
<button> | No | Use formtarget on submit buttons |
target vs window.open() vs same-tab links| Method | Pros | Cons |
|---|---|---|
target="_self" (default) | Predictable, accessible | User leaves current page |
target="_blank" | Keeps current page open | Needs noopener; can confuse users |
window.open() | Full JS control of size/position | Often blocked as pop-up |
Named iframe | Load content in-page | Must manage iframe accessibility |
Open in new tab, load into a named iframe, and set target dynamically with JavaScript.
Two links with different target behavior:
The standard pattern for external links:
<a
href="https://www.example.com"
target="_blank"
rel="noopener noreferrer">
Visit Example.com
</a>The link to https://www.example.com opens in a new tab because of target="_blank". The rel attribute prevents the new page from accessing window.opener.
Load a page inside an iframe instead of navigating away:
<a href="https://www.example.com" target="myFrame">Load in panel</a>
<iframe name="myFrame" title="Embedded content" width="600" height="300"></iframe>The custom name myFrame matches the iframe’s name attribute, so the link loads inside the iframe rather than replacing the whole page.
Change where a link opens based on conditions:
<a id="dynamicLink" href="https://www.example.com">Go to Example.com</a>
<script>
document.getElementById("dynamicLink").target = "_blank";
document.getElementById("dynamicLink").rel = "noopener noreferrer";
</script>In this script, target is set to _blank on the link with id dynamicLink. Useful when user preferences or context determine whether a link should open in a new tab.
_blank, indicate it visually or in link text (e.g. “opens in new tab”) so screen reader users are not surprised.rel="noopener noreferrer" — Protects all users from malicious redirect attacks via window.opener.title — Required for screen readers to describe embedded content.Activation.
Keyword or name.
Tab, frame, etc.
Where link opens.
The target attribute is universally supported. All major browsers honor _blank, _self, and named iframe targets.
Chrome, Firefox, Safari, and Edge all support target on links and forms.
Bottom line: Use target confidently; modern browsers implicitly apply noopener for _blank, but still include rel explicitly.
rel="noopener noreferrer" on target="_blank" links_self (default) for normal site navigationtitle_blank without rel="noopener" on untrusted sitesThe target attribute is a valuable tool for controlling how linked documents are displayed. By understanding values like _blank, _self, and custom frame names, you can provide a more tailored browsing experience.
Use it with care: secure external tabs with rel="noopener noreferrer", communicate new-tab behavior to users, and default to same-tab navigation whenever possible.
targetBookmark these when writing links.
Where link opens
PurposeNew tab
CommonSecurity
RequiredJavaScript
DynamicCustom target
Layouttarget="_blank" and add rel="noopener noreferrer"._self — the link opens in the same tab or frame.window.opener.link.target = "_blank" on an anchor element._parent targets the parent frame; _top breaks out to the full window.Try the _blank example with secure rel attributes.
5 people found this page helpful