Skip to main content
Practice

a Tag target Attribute

The target attribute of the <a> tag is used to specify whether the link should open in a new window or the current window.

a Tag target Attribute
<a href="link address" target="_blank">link text</a>
  • _blank: target="_blank" specifies that the link should open in a new window or tab. When clicked, the link address loads in a new window or tab, allowing the user to keep the original page open.

  • _self: target="_self" specifies that the link should open in the current window. This loads the link address in the current webpage, replacing its content. This means that the current page will be substituted with the new page upon clicking the link.


The following HTML code creates a link labeled "Go to Google" and specifies that it should open in a new window.

Open link in new window
<a href="https://www.google.com" target="_blank">Go to Google</a>

When you add the above code to a webpage, a link labeled "Go to Google" will be displayed. Clicking this link will open the Google website in a new window.

Want to learn more?

Join CodeFriends Plus membership or enroll in a course to start your journey.