How to open anchor tag in new tab
To open an anchor tag (<a>
) in a new tab, you can add the target
attribute and set its value to _blank
. Here's an example:
<a rel="nofollow" target="_blank" href="https://www.example.com" target="_blank">Open in new tab</a>
This will open the link in a new tab when the user clicks on it.
Alternatively, you can also use the rel
attribute and set its value to noopener
or noreferrer
to prevent the new tab from being treated as a referrer for the original page:
<a rel="nofollow" target="_blank" href="https://www.example.com" target="_blank" rel="noopener">Open in new tab</a>
Note that the target
attribute can also be set to other values, such as _self
(default), _parent
, _top
, or a specific frame name. However, _blank
is the most common value used to open a link in a new tab.
It's also worth noting that some browsers may have specific settings or extensions that can affect how links are opened in new tabs. For example, some browsers may have a setting to open links in new tabs by default, or an extension may be installed that modifies the behavior of links.