Base HTML

HTML <base> Tag

To specify a base URL or to specify a URL for all relative links within an HTML document, the HTML <base> tag is used. Within a document, only one <base> element can be specified and is placed within the <head> element. The HTML <base> element does not contain a closing tag but the XHTML <base> element does require the closing tag </base>. The HTML <base> tag must have either an “href” attribute specified with it or a “target” attribute specified with it. The “href” and the “target” attribute can also be specified together with the HTML <base> tag.

Syntax:

<base href="https://www.example.com">

Example 1:

<!DOCTYPE html>
<html>
<head>
<base href="https://www.w3schools.blog">
</head>
<body>
<p><img src="wp-content/uploads/2018/08/Bootstra
<p><a href="https://www.w3schools.blog">w3schools</a></p>
</body>
</html>

Explanation:

In the above example, the relative address for the image is specified. The browser will look for the image at “https://www.w3schools.blog/wp-content/uploads/2018/08/Bootstra

Example 2: Using _blank in <base> tag.

<!DOCTYPE html>
<html>
<head>
<base href="https://www.w3schools.blog/" target="_blank">
</head>
<body>
<p><img src="wp-content/uploads/2018/08/Bootstra
<p><a href="https://www.w3schools.blog">w3schools</a></p>
</body>
</html>

Explanation:

In the above example, the relative address for the image is specified. The browser will look for the image at “https://www.w3schools.blog/wp-content/uploads/2018/08/Bootstra

Tag Specific attributes:

Attribute Value Uses
href URL To define the base URL for all relative links.
target _blank To open the relative link in the next window.
target _self To open the relative link in the current window.
target _parent To open the relative link in the parent frame.
target _top To open the links at the full width of the page.

Global Attributes:

The HTML Global attributes are supported by the HTML <base> tag.

Event Attributes:

The HTML Event attributes are supported by the HTML <base> tag.

Supporting Browsers:

Chrome, IE, Firefox, Opera, and Safari.