The target
attribute in HTML links is used to specify where the linked document should be opened when the user clicks on the link. The target
attribute can be used to open the linked document in a new window or tab, or to load the linked document in a specific frame.
Here is an example of how to use the target
attribute to open a link in a new window:
<!DOCTYPE html>
<html>
<head>
<title>My Web Page</title>
</head>
<body>
<h1>Welcome to my web page!</h1>
<p>Check out my <a href="https://www.example.com" target="_blank">favorite website</a>.</p>
</body>
</html>
In this example, the target
attribute is set to _blank
, which tells the browser to open the linked document in a new window or tab. When the user clicks on the link, the linked document will be loaded in a new browser window or tab.
You can also use the target
attribute to open the linked document in a specific frame or iframe. For example:
<!DOCTYPE html>
<html>
<head>
<title>My Web Page</title>
</head>
<frameset cols="25%,75%">
<frame src="menu.html" name="menu">
<frame src="content.html" name="content">
</frameset>
<body>
<h1>Welcome to my web page!</h1>
<p>Check out my <a href="https://www.example.com" target="content">favorite website</a>.</p>
</body>
</html>
In this example, the HTML document uses frames to display two separate web pages side-by-side. The target
attribute of the link is set to content
, which tells the browser to load the linked document in the content
frame.
Note that the use of frames in HTML is not recommended, as it can cause issues with usability, accessibility, and search engine optimization. It is generally better to use modern HTML and CSS techniques to achieve the desired layout and functionality.