How to Use HTML to Open a Link in a New Tab

To open a link in a new tab using HTML, you need to add the target attribute with the value of “_blank” to the anchor tag (<a>).

Here’s an example code snippet:

php
<a href="https://www.example.com" target="_blank">Link Text</a>

In the above example, when a user clicks on the link, it will open the URL “https://www.example.com” in a new tab.

Note that the target attribute can also take other values besides “_blank” that control how the link will be opened. Here are some commonly used values:

  • _self (default): opens the link in the same window or tab
  • _parent: opens the link in the parent frame or window
  • _top: opens the link in the top-level frame or window

However, when you want to open a link in a new tab, you should use the value of “_blank” as shown in the example above.