How to make link open in new tab in html
To make a link open 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.
You can also use the target
attribute with other values, such as:
_self
: Opens the link in the same tab (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
For example:
<a rel="nofollow" target="_blank" href="https://www.example.com" target="_parent">Open in parent frame</a>
This will open the link in the parent frame if the link is inside a frame.
Note that the target
attribute only works for links that are not inside a form. If you have a link inside a form, you can use the formtarget
attribute instead:
<form>
<input type="submit" value="Submit">
<a rel="nofollow" target="_blank" href="https://www.example.com" formtarget="_blank">Open in new tab</a>
</form>
This will open the link in a new tab when the form is submitted.