<base>

The HTML <base> element sets a base URL for resolving all relative links and resources within a document, providing a reference point for those URLs.

<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

index.html
<base href="URL" target="window or frame">

<base> Demo

index.html
<!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

AttributeValueDescription
hrefURLDefines 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.
If multiple <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, the target 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.