HTML target Attribute

Beginner
⏱️ 6 min read
📚 Updated: Jun 2026
🎯 3 Examples
Links & Navigation

Introduction

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.

What You’ll Learn

01

_blank

New tab.

02

_self

Same tab.

03

Frame names

iframe target.

04

rel noopener

Security.

05

JavaScript

link.target.

06

A11y

New tab hints.

Purpose of target

The 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).

💡
Security with _blank

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).

📝 Syntax

Add target to an anchor with an href:

target.html
<a
  href="https://www.example.com"
  target="_blank"
  rel="noopener noreferrer">
  Visit Example.com
</a>

Syntax Rules

  • Most common on <a href="...">.
  • Also valid on <form> (see formtarget for submit buttons), <area>, and <base>.
  • Values: keyword (_blank, _self, _parent, _top) or a custom frame/window name.
  • Default when omitted: _self (same tab).
  • Custom names match name on <iframe> or window.open.
  • IDL property: HTMLAnchorElement.target.

💎 Values

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.
  • Custom name (e.g. myFrame) — Opens in a frame, iframe, or window with that name.

_blank

_blank.html
<a href="https://www.example.com" target="_blank" rel="noopener noreferrer">Visit Example.com</a>

_self

_self.html
<a href="https://www.example.com" target="_self">Visit Example.com</a>

_parent and _top

_parent-top.html
<a href="https://www.example.com" target="_parent">Parent frame</a>
<a href="https://www.example.com" target="_top">Top window</a>

Custom frame name

framename.html
<a href="page.html" target="myFrame">Load in iframe</a>
<iframe name="myFrame" title="Content panel"></iframe>

⚡ Quick Reference

ValueOpens inCommon use
_blankNew tab/windowExternal links
_selfSame tab (default)Normal navigation
_parentParent frameLegacy framesets
_topFull windowBreak out of frames
frameNameNamed iframeSplit layouts
With _blankrel="noopener noreferrer"Security best practice

Applicable Elements

ElementSupported?Notes
<a href>YesMost common usage
<form>YesWhere form submission opens
<area>YesImage map links
<base>YesDefault target for all links on page
<button>NoUse formtarget on submit buttons

target vs window.open() vs same-tab links

MethodProsCons
target="_self" (default)Predictable, accessibleUser leaves current page
target="_blank"Keeps current page openNeeds noopener; can confuse users
window.open()Full JS control of size/positionOften blocked as pop-up
Named iframeLoad content in-pageMust manage iframe accessibility

Examples Gallery

Open in new tab, load into a named iframe, and set target dynamically with JavaScript.

Example — open in new tab

The standard pattern for external links:

target.html
<a
  href="https://www.example.com"
  target="_blank"
  rel="noopener noreferrer">
  Visit Example.com
</a>
Try It Yourself

How It Works

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.

Example — named iframe target

Load a page inside an iframe instead of navigating away:

iframe-target.html
<a href="https://www.example.com" target="myFrame">Load in panel</a>
<iframe name="myFrame" title="Embedded content" width="600" height="300"></iframe>

How It Works

The custom name myFrame matches the iframe’s name attribute, so the link loads inside the iframe rather than replacing the whole page.

Dynamic Values with JavaScript

Change where a link opens based on conditions:

dynamic-target.html
<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>

How It Works

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.

♿ Accessibility

  • Warn about new tabs — If using _blank, indicate it visually or in link text (e.g. “opens in new tab”) so screen reader users are not surprised.
  • Use rel="noopener noreferrer" — Protects all users from malicious redirect attacks via window.opener.
  • Give iframes a title — Required for screen readers to describe embedded content.
  • Avoid unexpected new windows — Opening tabs without warning harms navigation predictability.
  • Prefer same-tab for essential flow — Multi-step tasks should usually stay in one tab.

🧠 How target Works

1

User clicks link

Activation.

Action
2

Browser reads target

Keyword or name.

Parse
3

Opens context

Tab, frame, etc.

Navigate
=

Controlled navigation

Where link opens.

Browser Support

The target attribute is universally supported. All major browsers honor _blank, _self, and named iframe targets.

Universal · Fully supported

Works everywhere

Chrome, Firefox, Safari, and Edge all support target on links and forms.

100% Modern browsers
Google Chrome All versions
Supported
Mozilla Firefox All versions
Supported
Apple Safari All versions
Supported
Microsoft Edge All versions
Supported
target attribute Excellent

Bottom line: Use target confidently; modern browsers implicitly apply noopener for _blank, but still include rel explicitly.

💡 Best Practices

✅ Do

  • Add rel="noopener noreferrer" on target="_blank" links
  • Tell users when a link opens in a new tab
  • Use _self (default) for normal site navigation
  • Give named iframes a descriptive title
  • Test links across browsers

❌ Don’t

  • Open every external link in a new tab without reason
  • Use _blank without rel="noopener" on untrusted sites
  • Rely on pop-up windows users may block
  • Use framesets when modern layouts (CSS Grid/Flexbox) suffice
  • Hide that navigation will leave the current context

Conclusion

The 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.

Key Takeaways

Knowledge Unlocked

Five truths every developer should know about target

Bookmark these when writing links.

5
Core concepts
📄 02

_blank

New tab

Common
🔒 03

noopener

Security

Required
⚙️ 04

link.target

JavaScript

Dynamic
💻 05

iframe name

Custom target

Layout

❓ Frequently Asked Questions

It specifies where to open the linked document—same tab, new tab, or a named frame.
Use target="_blank" and add rel="noopener noreferrer".
_self — the link opens in the same tab or frame.
It prevents the new page from controlling your original tab through window.opener.
Yes. Use link.target = "_blank" on an anchor element.
Legacy frame navigation—_parent targets the parent frame; _top breaks out to the full window.

Practice opening links in new tabs

Try the _blank example with secure rel attributes.

Try _blank example →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful