- 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 - <base> Tag
In recent times, HTML5 has added the <base> tag. For every relative URL in the HTML document, it defines an absolute (base) URL. Additionally, this element specifies how links in the current document must be opened (in a new window, in the current window, etc.).
The <head> element include the only one <base> tag that can be used on the page. It must be inserted as soon as possible because its action extends at the place where it is given.
Only the first href and target attributes will be followed if you use multiple <base> element. The rest won't be considered.
Syntax
Following is the syntax of <base> tag −
<base href = "SAMPLE_URL">
Specific Attributes
The HTML <base> tag also supports the following additional attributes −
S.No. | Attribute & Description |
---|---|
1 | href Specifies the URL of a page or the name of the anchor that the link goes to. |
2 | target Where to open the target URL. |
Example
Following is a basic example of the usage of the <base> tag.
<!DOCTYPE html> <html> <head> <title>HTML base Tag</title> <base href="https://www.tutorialspoint.com" /> </head> <body> HTML: <img src="https://www.tutorialspoint.com/cg/images/logo.png" /> </body> </html>
On running the above code, it will generate an output consisting of the image that gets uploaded to the webpage along with text.
Example
Let’s look at the following example, where we are going to set the default target for all the URLs on the page.
<!DOCTYPE html> <html> <head> <base href="https://www.tutorialspoint.com/index.htm" target="_blank"> </head> <body style="background-color:#D5F5E3"> <p> <img src="https://www.tutorialspoint.com/cg/images/logo.png" height="39" alt="logo"> - Tutorials Point originated from the idea that there exists a class of readers who respond better to online content and prefer to learn new skills at their own pace from the comforts of their drawing rooms. </p> <p> <a href="https://www.tutorialspoint.com/html/index.htm">HTML Tutorial</a> </p> </body> </html>
When we execute the above code, the output window will pop up, displaying the image along with text and a link to the webpage. When the user clicks on the link, it opens in a new window even though the target is not set. It opens in a new window because the target of the base element is set to target=_blank.
Example
Consider another scenario where we are going to take the base URL, which all the relative links treat as the starting URL and opens in the same window.
<!DOCTYPE html> <html> <head> <title>Base tag</title> <style> a { text-decoration: none; color: black; } a:hover { color: green; font-size: 20px; } </style> <base href="https://www.tutorialspoint.com/index.htm"> </head> <body style="background-color:#D6EAF8 "> <h2 style="color: #DE3163; font-size: 30px; font-style: verdana;">List of Courses</h2> <a href="https://www.tutorialspoint.com/html/index.htm">HTML tutorial</a> <br> <a href="https://www.tutorialspoint.com/artificial_intelligence/index.html">AI tutorial</a> <br> <a href="https://www.tutorialspoint.com/data_structures_algorithms/index.htm">Data Structure tutorial</a> <br> <a href="https://www.tutorialspoint.com/cloud_computing/index.htm">Cloud Computing tutorial</a> <br> </body> </html>
On running the above code, it will generate an output consisting of links along with applied CSS displayed on the webpage. When the user clicks on the link, it will open the page within the same window.
To Continue Learning Please Login
Login with Google