Target attribute in HTML
What is the target attribute?
The target attribute in HTML specifies where a link should open when users click on it. The target attribute can take the following values:
- _blank
- _self
- _parent
- _top
The default value for the target attribute is _self, which means that the link will open in the same window or tab as the current page.
When to use the target attribute
The target attribute should be used when you want to control where a link will open. For example, you might use the target attribute to:
- Open a link in a new window or tab
- Open a link in a specific frame or iframe
- Open a link in a specific window or tab and give it a specific name
How to use the target attribute
To use the target attribute, simply add it to the <a> tag for the link. For example, the following code will open the link in a new window or tab:
<a href="https://www.example.com" target="_blank">Example link</a>
You can also use the target attribute to open a link in a specific frame or iframe. For example, the following code will open the link in the frame with the name "myframe":
<a href="https://www.example.com" target="myframe">Example link</a>
Finally, you can use the target attribute to open a link in a specific window or tab and give it a specific name. For example, the following code will open the link in a new window or tab with the name "mywindow":
<a href="https://www.example.com" target="_blank" name="mywindow">Example link</a>
Comments