HTML Link Target Attribute
By default, when a hyperlink is clicked, the target web page is displayed in the current browser window.
However, we can change this behavior using an additional attribute target
with any of the below values.
- target="_self" (default, opens target resource in the same window/tab)
- target="_blank" (opens target resource in a separate window or tab)
- target="_parent" (opens target resource inside the parent frame)
- target="_top" (opens target resource in the full body of the window)
<a href="https://randomcodez.com" target="_blank">Random Codez Website</a>
Examples
<!doctype html>
<html lang="en">
<head>
</head>
<body>
<h1>HTML Link Target Attribute</h1>
<a href="https://randomcodez.com" target="_self">Link with target(_self, which is default)</a><br>
<a href="https://randomcodez.com" target="_blank">Link with target(_blank)</a><br>
<a href="https://randomcodez.com" target="_parent">Link with target(_parent)</a><br>
<a href="https://randomcodez.com" target="_top">Link with target(_top)</a><br>
</body>
</html>
Overall
HTML link target attribute helps us overwrite its default behavior.