Open In App

What is the use of target Attribute in <a> Tags ?

Last Updated : 26 Feb, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

The “target” attribute in <a> tags are used to specify where the linked document should be displayed when the user clicks on the link. It determines the browser context in which the linked content will open, such as in a new window, a new tab, or the same frame or window.

Syntax

<a href="URL" target="_blank">Link Text</a>
Key Point Description
Target Values The “target” attribute accepts various values, including “_blank” (opens the link in a new window or tab), “_self” (opens the link in the same frame or window), “_parent” (opens the link in the parent frame or window), and “_top” (opens the link in the top-level browsing context).
Default Behavior If the “target” attribute is omitted, the linked document typically opens in the same browsing context, unless overridden by browser settings or other attributes.
Accessibility Care should be taken when using the “target” attribute to ensure that users are not unexpectedly taken away from the current page, especially users with screen readers or other assistive technologies.
Security Considerations Opening links in a new window or tab (“_blank”) may be perceived as a security risk due to potential phishing attacks or unwanted pop-ups.

Features

  • Opening in New Window or Tab: Use the “target” attribute with the value “_blank” to open the linked document in a new browser window or tab.
<a href="https://example.com" target="_blank">Visit Example</a>
  • Opening in Same Frame or Window: Specify “_self” as the “target” attribute value to open the linked document in the same frame or window.
<a href="https://example.com" target="_self">Visit Example</a>

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads