HTML base Tag

HTML base Tag defines a base URL for all the links on the HTML Document or Web Page.

Syntax of HTML base Tag

The Syntax of HTML base Tag is shown below. It is self closing tag. While in XHTML it has both starting and ending tag.

<!DOCTYPE html>
<html>
<head>
<base href="https://www.howtocodeschool.com/">
</head>
<body>
</body>
</html>

Usage of HTML base Tag

HTML Base Tag defines the base url or target for all other urls or links defined in the HTML Document or Web Page. There is only one base url allowed in one web page. There can't be more than one base urls.

Example of HTML base Tag

Simple example of base tag is given below.

<!DOCTYPE html>
<html>
<head>
<base href="https://www.howtocodeschool.com/">
</head>
<body>
<a href="html-base-tag.html">HTML Base Tag</a>
</body>
</html>

In the above example as you can see, the Base Url of HTML Base Tag link is defined in the head section of document.

Browser Support for HTML base Tag

HTML Base Tag is supported by all major browsers including Internet Explorer.

Attributes used in HTML base Tag

Two main attributes defined inside HTML base tags are href and target attributes. If href is not defined in base tag then target attribute must be defined or you can define both.

href attribute

It sets the Base URL of web page or document.

target attribute

It defines the target of where to open the linked document or page or file.

Global Attributes Support in HTML base Tag

The HTML Base Tag supports Global Attributes.

Event Attributes Support in HTML base Tag

The HTML Base Tag doesn't support Event Attributes.

HTML base Tag Video

Watch our video on HTML base Tag and subscribe our Youtube Channel.