Target attribute
The target attribute is an attribute of the a anchor tag in HTML that defines the browsing context in which a destination page should open when the link is clicked. Put simply, it decides whether the new page appears in the same tab, a new tab or a specific frame. It is a seemingly minor detail that has a real effect on user experience and security.
How the target attribute works
The attribute accepts several special values:
- _self — opens the link in the same window or tab (the default);
- _blank — opens the link in a new tab or window;
- _parent — opens in the frame that is parent to the current one;
- _top — opens in the full window, breaking out of all frames.
You can also supply a custom name so that subsequent links open in that same named tab. In practice the first two values are by far the most common, while the others relate to increasingly rare framesets.
Practical application
The _blank value is used when you do not want the user to leave the current page — for example, links to external sources, terms of service, or PDF documents opened while filling in a form. It should be used in moderation, though: from a UX standpoint, multiplying tabs can be disorienting and breaks the back button. Security matters too: links opened with target="_blank" should carry rel="noopener" (and often noreferrer) to prevent a tabnabbing attack, in which the opened page gains partial control over the source tab. This is one of the recommendations that fits into broader front-end security best practices.
From an accessibility standpoint, it is worth remembering that suddenly opening a new tab can surprise people using screen readers, because the context change happens without a clear warning. A good practice is to signal this behaviour — for example with an icon or a text note next to a link that opens in a new window. That way the user knows what to expect, and the page stays predictable and aligned with inclusive design principles, whatever value the target attribute takes.
Powiązane pojęcia
Najczęstsze pytania
When should a link open in a new tab with target="_blank"?
The rule is to use it sparingly. A new tab makes sense for external links, forms or documents the user does not want to lose sight of. Opening internal links in new tabs is often annoying, because it takes control of navigation away from the user and breaks the back button.
Why add rel="noopener" alongside target="_blank"?
Without it, the page opened in a new tab gains partial access to the source page through the window.opener object, enabling a tabnabbing attack. Adding rel="noopener" (often with noreferrer) severs that link and protects the user. Modern browsers do this by default, but stating it explicitly is safer.
