Html code to open a link in new tab
To open a link in a new tab, you can use the target
attribute in the a
tag and set its value to _blank
. Here is the HTML code:
<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.
You can also use the rel
attribute to specify that the link should be opened in a new tab. The value noopener
is recommended to prevent the new tab from accessing the parent page's cookies and other data.
<a rel="nofollow" target="_blank" href="https://www.example.com" rel="noopener noreferrer" target="_blank">Open in new tab</a>
Note that the noopener
value is not supported in older browsers, so you may want to use the target
attribute alone if you need to support older browsers.
It's also a good practice to use the href
attribute to specify the URL of the link, and the title
attribute to specify the title of the link.
<a rel="nofollow" target="_blank" href="https://www.example.com" title="Example website" rel="noopener noreferrer" target="_blank">Open in new tab</a>
This way, you can provide a clear and descriptive title for the link, and also specify the URL and the target attribute to open the link in a new tab.