How do you open a link in a new tab in HTML?
To open a link in a new tab, use the target="_blank" attribute on the <a> tag.
Example:
html
<a href="https://example.com" target="_blank">Open in a new tab</a>On click, the https://example.com page opens in a new browser tab, while the current one stays open.
It is also recommended to add the rel="noopener noreferrer" attribute
This protects against potential vulnerabilities (so the opened page cannot get access to the original tab).
Safe variant:
html
<a href="https://example.com" target="_blank" rel="noopener noreferrer">
Open in a new tab
</a>Briefly:
target="_blank": opens the link in a new tab.rel="noopener noreferrer": protects the original page.
Summary:
html
<a href="https://example.com" target="_blank" rel="noopener noreferrer">Go</a>Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.