A href code to open in new tab
To open a link in a new tab using HTML, you can use the target
attribute and set its value to _blank
. Here is the syntax:
<a rel="nofollow" target="_blank" href="https://www.example.com" target="_blank">Link Text</a>
This will open the link in a new tab or window when clicked.
Note: You can also use target="_new"
or target="_noopener"
instead of _blank
, but _blank
is the most commonly used and supported option.
Here are some additional options you can use with the target
attribute:
_self
: Opens the link in the same tab or window (default behavior)_parent
: Opens the link in the parent frame (if the link is inside a frame)_top
: Opens the link in the full body of the window (if the link is inside a frame)_blank
: Opens the link in a new tab or window_noopener
: Opens the link in a new tab or window, but does not allow the new page to access the parent page's context (e.g. cookies, local storage)
For example:
<a rel="nofollow" target="_blank" href="https://www.example.com" target="_self">Link Text</a> <!-- opens in same tab -->
<a rel="nofollow" target="_blank" href="https://www.example.com" target="_parent">Link Text</a> <!-- opens in parent frame -->
<a rel="nofollow" target="_blank" href="https://www.example.com" target="_top">Link Text</a> <!-- opens in full body of window -->
<a rel="nofollow" target="_blank" href="https://www.example.com" target="_blank">Link Text</a> <!-- opens in new tab or window -->
<a rel="nofollow" target="_blank" href="https://www.example.com" target="_noopener">Link Text</a> <!-- opens in new tab or window, without access to parent page's context -->