HTML <base> tag

The <base> tag defines the base URL/target value for all relative URLs in a web-page or document. The base URL is valid only when you have not assigned the specific href value for an HTML <a> element.

Type: Null or zero

Syntax of <base> tag

<base href="URL" target="_blank">

All the links in the document will be opened in a new tab or window to the given URL because we set the base target as "URL" with "_blank" target.

Characteristics of <base> tag

  1. The <base> tag is considered as a null or zero tag because it has no end tag (</base>).
  2. It must be defined within the <head> element like
  3. It is an optional meta tag, meaning it may or may not be added, depending on the author.
  4. The maximum <base> element that be can defined within a document is only one.
  5. To define <base> tag, you must use either at least one of the href and target attributes or you may use both like

Supported Browsers

Tag Chrome Internet Explorer Firefox Safari Opera Mini
<base> Yes Yes Yes Yes Yes

Full code example

<!DOCTYPE html>
<html>
<head>
<base
 href="/html_a_tag.html"
 target="_blank">
</head>
<body>
<p><a href=" "> HyperLink </a> allows you to move from one page to another. All the links in this document will open in the /html_a_tag.html page and also in a new tab.
<br>
But, <a href="html_b_tag.html">this link</a> will not open in the base URL ("/html_a_tag.html") because a specific URL is defined for this link.
</p>
</body>
</html>
Run The code »

Output on the browser

HyperLink allows you to move from one page to another. All the links in this document will open in the /html_a_tag.html page and also in a new tab.
But, this link will not open in the base URL ("/html_a_tag.html") because a specific URL is defined for this link.

If you give a specific URL for a link like <a href = "URL1">, the link will redirect to URL1 but not on the <base> tag value (URL)
Specific URL > Base URL.

Attributes of <base> tag

There are two attributes of <base> tag:- href and target. You can use either both attributes or single. Note that if you use neither of its attribute to the <base> tag, you have no reason for assigning this tag.

  1. href: It specifies the base URL for all relative URLs in a web-page or document. The value of the href attribute is "URL".

    Syntax:

    <base href="URL">
    
  2. target: It specifies the base target (outcome of the link after click) for all relative URLs in a web-page or document. The _blank target is used only when the href attribute is used. By default, the href target is _self. The most common href target is _blank and _self. The value of the href attribute can be _self, _blank, _parent and _top.

    Syntax:

    <base href="URL" target="_self | _blank | _parent | _top">
    

    href target values

    Value Note
    _self It opens the linked document in the same window or tab. This is the default value if not set any value.
    _blank It opens the linked document in a new window or tab. When the users click on a link having _blank value, the link will open in a separate window.
    _parent It opens the linked document in the active frame of a window.
    _top It opens the linked document in full size of the window.

More reference

Note that the most effective use of the <base> tag is to define a parent directory for all included links; instead of writing /html/html-a-tag/, /html/html-b-tag/, etc., you can set the base URL as /html/ so links can be written simply as /html-a-tag/ and /html-b-tag/.