- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to change the target of a link in HTML?
We use the target attribute of the <a>…</a> tag, to change the target value of the link. The target attribute can be used to open any link in a new tab, current tab and so on.
_blank − link will open in a new tab.
_self − link will open in the current tab.
_parent − link will open in a parent frame.
_top − link will open in the top frame.
Syntax
Following is the syntax to change the target of a link in HTML.
<a href="link…" target="_parent|_blank|_self|_top">Link text…</a>
Example
Following is the example program to change the target value of a link.
<!DOCTYPE html> <html> <head> <style> a:link { color: greenyellow; background-color: transparent; text-decoration: none; } a:visited { color: deepskyblue; background-color: transparent; text-decoration: none; } a:active { color: yellow; background-color: transparent; } </style> </head> <body> <a href="https://www.youtube.com/watch?v=qz0aGYrrlhU" target="_blank">HTML Tutorial</a> </body> </html>
When we click on the link, the link will open in the new tab.
Example
Following another the example program to change the target value of a link.
<!DOCTYPE html> <html> <head> </head> <body> <a href="https://www.Google.com" target="_top">Google</a><br> </body> </html>
After clicking the link above, it will open in the top frame.
Example
Following is one more example program to change the target value of a link.
<!DOCTYPE html> <html> <head> </head> <body> <a href="https://www.Brave.com" target="_self">Brave</a> <br> <a href="https://www.Yahoo.com" target="_parent">Yahoo</a> </body> </html>
On executing the above program, a page with two links is generated (Brave and Yahoo). When we click on the Bravo link, link will open in the self-frame. When we click on the yahoo, link will open in the parent frame.