W3docs

HTML <base> Tag

HTML <base> Tag specifies an absolute URL for all relative URLs in the HTML document. It determines how links in the current document should be opened.

The <base> tag has been part of HTML since HTML 2.0. It defines an absolute (base) URL for all relative URLs in the HTML document, including links, images, forms, and scripts. This tag also determines how links in the current document should be opened (in a new window, in the current window, etc.).

You can access the used base URL of a document from scripts with document.baseURI. If the document doesn’t contain any <base> element, baseURL will default to document.location.href.

Syntax

The <base> tag is a void element, which means that the closing tag isn’t required. In HTML5, the self-closing slash is optional, but in XHTML, the <base> tag must be closed (<base />).

Tip

Only one <base> tag can be used on the page, and it must be placed in the <head> element. You must insert it as soon as possible since its action extends from the place where it is specified.

Danger

If you use multiple <base> elements, only the first href and target attributes will be obeyed. The rest will be ignored.

Example of the HTML <base> tag:

<!DOCTYPE html>
<html>
  <head>
    <title>HTML base tag</title>
    <base href="https://www.w3docs.com/" target="_blank" />
  </head>
  <body>
    <a href="/css3-maker/border-radius">Try CSS Maker Tool</a>
  </body>
</html>

Result

base example

In this example, the <base> tag defines the base URL - "https://www.w3docs.com/", and the relative link "/css3-maker/border-radius" will use that URL as a starting point.

Copy the above-mentioned code into our editor, and you will see an active link, which, when clicked, opens in a new window. Although the link itself does not contain the target="_blank" attribute, it will open in a new window, since we have set the target="_blank" attribute on the <base> tag.

Attributes

The <base> tag may contain either the href or target attribute, or both. If neither is specified, the tag has no effect.

AttributeValueDefinition
hrefURLSpecifies the base URL for all relative URLs on the page.
target_blankOpens the link in a new window or tab.
_selfOpens the link in the current window.
_parentOpens the link in the parent frame.
_topOpens the document in the full body of the window.

Practice

Practice

What is the function of the HTML <base> tag?