HTML <base> tag

Use of <base> tag

The <base> tag defines the base URL/target value for all relative URLs in a web-page or a document.
The base URL is valid only when you have not assigned the specific href value for an HTML <a> element. If you give specific URL for a link like <a href = "URL1">, the links will go to URL1 but not on URL (which is the default href values of base tag). See example
Type:Null or zero

Example of <base> tag

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

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

Characteristics of <base> tag

1. The <base> tag is null or zero tag because it has no end tag or close tag like </base> tag.
2. The <base> tag should be defined within the head element like

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

3. It is optional meta-tag element. i.e. it can add or not, which depends on the author.
4. The maximum <base> tag that be can defined within a document is only one. i.e. it cannot have more than one.
The following example is false.

<head>
    <base href = "URL" target = "_blank">
    <base href = "URL" target = "_self">
</head>

5. Inorder to define <base> tag, you should use either at least one attribute between href and target attribute or you can use both attributes.
The following example is invalid.

<head>
    <base>
</head>

Supported Browsers

Tag Chrome browser Internet explorer browser Firefox browser Safari browser Opera browser
<base> Yes Yes Yes Yes Yes

Full Code Examples

<!DOCTYPE html>
<html>
<head>
<base href = "a_tag.html" target = "_blank">
</head>
<body>
<p>
<a href = " "> HyperLink </a> allows to move from one page to another. <br>
To Learn anchor tag, <a href = " "> click here. </a>
</p>
<p>
All the links for this will be opened in the a_tag.html page also in the new target.
</p>
<p>
But <a href = "tag_b.html"> this link </a> will not opened in the base URL because we specify a particular URL for this link. </p>
</body>
</html>

Output

HyperLink allows to move from one page to another.
To Learn anchor tag, click here.
All the links for this will be opened in the a_tag.html page also in the new target.
But this link will not opened in the base URL because we specify a particular URL for this link.

Attributes of <base> tag

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

href attribute

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

    <base href = "URL">

target attribute

It specifies the base target (outcome of the link after click) for all relative URLs in a web-page or a 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 href attribute is _blank or _self or _parent or _top.

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

href target values

Value Notes
_self It opens the linked document in the same window or tab.
This is the default value if you are not setting 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.