How to open link in new tab html
To open a link in a new tab in HTML, you can use 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>
Or:
<a rel="nofollow" target="_blank" href="https://www.example.com" target="_blank" rel="noreferrer">Open in new tab</a>
Note that the noopener
and noreferrer
values are not supported in older browsers, so you may want to use the target="_blank"
approach instead.
You can also use JavaScript to open a link in a new tab:
<a rel="nofollow" target="_blank" href="https://www.example.com" onclick="window.open(this.href, '_blank'); return false;">Open in new tab</a>
This will open the link in a new tab when the user clicks on it, and prevent the default link behavior from occurring.
It's worth noting that some browsers may have different behaviors when it comes to opening links in new tabs, so it's always a good idea to test your code in different browsers to ensure it works as expected.