<base>
<base>
Tag
The <base>
element specifies a base URL for relative URLs in a document. It is typically used within the <head>
section to set a base path for all relative links, making it easier to manage and update links across a website.
Syntax
<base href="URL" target="window or frame">
<base>
Demo
<!DOCTYPE html>
<html>
<head>
<base href="https://institute.qarpeo.com">
<base target="_blank">
</head>
<body>
<img src="img.jpg">
<a href="https://institute.qarpeo.com" target="_blank">https://institute.qarpeo.com</a>
</body>
</html>
Attributes
Attribute | Value | Description |
---|---|---|
href | URL | Defines the base URL for all relative links on the page |
target | _blank _parent _self _top | Specifies where hyperlinks and forms should open by default |
href
Specifies the base URL for relative URLs in the document. Must be placed before any other elements with URL attributes. Accepts both absolute and relative URLs.
target
Defines where to display the result of hyperlinks or forms that lack an explicit target. It can be a browsing context name (e.g., tab, window, iframe) or a keyword:
_self
: Loads in the same browsing context (default)._blank
: Opens in a new, unnamed context._parent
: Loads in the parent context, or behaves like_self
if none exists._top
: Loads in the top-level context, or behaves like_self
if none exists.
<base>
elements are specified, only the first href
and first target
value are used; all others are ignored.Purpose and Function
The <base>
tag defines the base URL and/or target setting for all relative links within a webpage.
- It must include either the
href
attribute, thetarget
attribute, or both. - A document can only contain one
<base>
element. - This tag should be placed inside the
<head>
section of the HTML document.
Conclusion
The <base>
tag sets a base URL for all relative links within a document, simplifying link management. It can also define a default target for hyperlinks and forms, controlling where they open. The <base>
tag must be placed in the <head>
section, and a document can only contain one <base>
element.
<applet>
The <applet> tag allowed the inclusion of Java applets in web documents, but it's no longer supported in HTML5 because of security concerns.
<script>
The HTML <script> element allows you to include executable JavaScript code in a webpage, enabling client-side scripting and dynamic features, or you can link to external JavaScript files.