- HTML Tutorial
- HTML - Home
- HTML - History and Evolution
- HTML - Overview
- HTML - Editors
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Headings
- HTML - Paragraphs
- HTML - Quotations
- HTML - Comments
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Style Sheet
- HTML - CSS Classes
- HTML - CSS IDs
- HTML - Images
- HTML - Image Map
- HTML Tables
- HTML - Tables
- HTML - Headers & Caption
- HTML - Table Styling
- HTML - Table Colgroup
- HTML - Nested Tables
- HTML Lists
- HTML - Lists
- HTML - Unordered Lists
- HTML - Ordered Lists
- HTML - Definition Lists
- HTML Links
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Iframes
- HTML - Blocks
- HTML Backgrounds
- HTML - Backgrounds
- HTML Colors
- HTML - Colors
- HTML - RGB
- HTML - HEX
- HTML - HSL
- HTML Forms
- HTML - Forms
- HTML - Form Attributes
- HTML - Form Control
- HTML - Input Attributes
- HTML Media
- HTML - Video Element
- HTML - Audio Element
- HTML - Embed Multimedia
- HTML Header
- HTML - Head Element
- HTML - Adding Favicon
- HTML - Javascript
- HTML Layouts
- HTML - Layouts
- HTML - Layout Elements
- HTML - Layout using CSS
- HTML - Responsiveness
- HTML - Symbols
- HTML - Emojis
- HTML - Style Guide
- HTML Graphics
- HTML - SVG
- HTML - Canvas
- HTML APIs
- HTML - Geolocation API
- HTML - Drag & Drop API
- HTML - Web Workers API
- HTML - WebSocket
- HTML - Web Storage
- HTML - Server Sent Events
- HTML Miscellaneous
- HTML - MathML
- HTML - Microdata
- HTML - IndexedDB
- HTML - Web Messaging
- HTML - Web CORS
- HTML - Web RTC
- HTML Demo
- HTML - Audio Player
- HTML - Video Player
- HTML - Web slide Desk
- HTML Tools
- HTML - Velocity Draw
- HTML - QR Code
- HTML - Modernizer
- HTML - Validation
- HTML - Color Code Builder
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
- HTML Resources
- HTML - Quick Guide
- HTML - Useful Resources
- HTML - Color Code Builder
- HTML - Online Editor
HTML - target Attribute
The target is an HTML attribute that is used to specify where to open the linked document. It is used with the anchor <a>, <area>, <base>, and <form> tags.
The target attribute specifies the default target for all hyperlinks and forms in the page for the <base> tag. And this attribute specifies a name or a keyword that indicates where to display the response that is received after submitting the form for the <form> tag.
Syntax
Following is the syntax of the target attribute −
<element target = "_blank | _self | _parent | _top | framename " \>
Following are the attribute values –
- _blank − it opens the link in a new window.
- _self − it opens the link in a same frame it is a default value.
- _parent − it opens the link in the parent frameset.
- _top − it opens the linked document in the full body of the window.
- frameset − it opens the linked document in the named frame.
Example
In the following example, let’s see the usage of target attribute along with value "_blank".
<!DOCTYPE html> <html> <body> <h3>tutorialspoint</h3> <h2>target attribute</h2> <p>Open link in a new window or tab: <a href="https://www.tutorialspoint.com/index.htm" target="_blank">Visit tutorialspoint</a> </p> </body> </html>
On running the above code, the output window will pop up displaying the hyperlink on the webpage. when the user clicks on the hyperlink it will opens in new tab.
Example
Considering the another scenario, where we are going to use the target attribute with the value '_self'.
<!DOCTYPE html> <html> <body> <h3>tutorialspoint</h3> <h2>target attribute</h2> <p>Open link in a same window or tab: <a href="https://www.tutorialspoint.com/index.htm" target="_self">Visit tutorialspoint</a> </p> </body> </html>
When we run the above code, it will generate an output consisting of the hyperlink displayed on the webpage. when the user clicks on the link it will opens in the same tab itself.
Example
Let's look into the following example, where we are going to use the target attribute with the value '_parent'.
<!DOCTYPE html> <html> <body> <h3>tutorialspoint</h3> <h2>target attribute</h2> <p>Open link in a parent tab: <a href="https://www.tutorialspoint.com/index.htm" target="_parent">Visit tutorialspoint</a> </p> </body> </html>
On running the above code, the output window will pop up displaying the hyperlink on the webpage. when the user clicks on the link it will opens in the same frameset.
Example
Following is the example, where we are using the <base> tag with the target attribute, and the value of the target is "_self"
<!DOCTYPE html> <html> <head> <base target="_self"> <title> HTML Base target Attribute </title> </head> <body style="text-align:center;"> <h1 style="color:green;">tutorials <span style="color: black">point</span> </h1> <h2>HTML Base target Attribute</h2> <a href="https://www.tutorialspoint.com/index.htm" alt="GFG"> visit tutorialspoint </a> </body> </html>
When we run the above code, it will generate an output consisting of the text along with a hyperlink displayed on the webpage. when the user clicks on the link it will open in the same tab or window.
To Continue Learning Please Login
Login with Google