Open In App

How to use the target attribute and the rel attribute in the <a> Tag ?

Last Updated : 31 Jan, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

The target and rel attributes in the <a> (anchor) tag is used to control the behaviour of hyperlinks, specifying how the linked content should be opened and establishing relationships between the current and linked documents. Here’s how to use these attributes:

target Attribute:

The target attribute determines where the linked content will be displayed. Common values for the target attribute are:

  • _blank html: Opens the linked document in a new browser window or tab.
  • _self: Opens the linked document in the same frame or window.
  • _parent: Opens the linked document in the parent frame.
  • _top: Opens the linked document in the full body of the window.

Syntax:

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

rel Attribute:

The rel attribute establishes relationships between the current document and the linked document. Common values for the rel attribute include:

  • nofollow: Informs search engines that the link should not influence the ranking of the link’s target in the search engine’s index.
  • noopener: Advises the browser not to open the linked page in a way that allows it to affect the context of the referring page.
  • noreferrer: Specifies that no referrer information should be passed along with the request.
<a href="https://www.example.com" rel="nofollow">Visit Example Website</a>

Combined Usage:

You can use both attributes together for more control over link behavior.

<a href="https://www.geeksforgeeks.org" 
target="_blank" rel="noopener noreferrer">
Visit Example Website
</a>

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads