The <a>
tag, also known as the anchor tag, is used to create a hyperlink to another web page or a specific location on the same page. The href attribute is used to specify the destination of the link.
Example:
<a href="https://www.example.com">Visit Example</a>
This will create a link that, when clicked, takes the user to the website https://htmltutorial.xyz. The text “Visit Example” will be displayed on the page as the clickable link.
Example:
<p>Check out our <a href="https://htmltutorial.xyz/index.php/2023/01/17/html-heading-tags-importance-usage-seo-best-practices/">Heading Tag</a> for more information.</p>
<h2>Related Articles</h2>
<ul>
<li><a href="#article1">Article 1</a></li>
<li><a href="#article2">Article 2</a></li>
<li><a href="#article3">Article 3</a></li>
</ul>
In the above example, first link will take user to another website’s blog page and second links will take user to specific sections within the same blog post.
Specify a location for Link using target attribute
The target
attribute of the <a>
tag can be used to specify where a link should open. The most common values for this attribute are:
_blank
: This value will open the link in a new browser window or tab.
<a href="https://www.example.com" target="_blank">Visit Example</a>
_self
: This value will open the link in the same window or tab. This is the default value if the target
attribute is not specified.
<a href="https://www.example.com" target="_self">Visit Example</a>
_parent
: This value will open the link in the parent frame.
<a href="https://www.example.com" target="_parent">Visit Example</a>
_top
: This value will open the link in the full body of the window, breaking out of any frames.
<a href="https://www.example.com" target="_top">Visit Example</a>
name
: This value will open the link in a named target frame.
<a href="https://www.example.com" target="frame_name">Visit Example</a>
It’s important to note that using target="_blank"
will open the link in a new tab, but it also disables the “back” button on the browser, which can cause confusion for users. To avoid this, it’s better to use target="_self"
or target="_top"
.