HTML - <base> Tag



HTML <base> tag is used to speficify base URL. There should be href and target attribute in the <base> tag.

Additionally, this element specifies how links in the current document must be opened. HTML <head> element include the only one <base> tag that can be used on the page. It must be inserted as soon as possible because its action extends at the place where it is given.

Only the first href and target attributes will be followed if you use multiple <base> element. The rest won't be considered.

Syntax

<base href="" target="">

Attribute

HTML base tag supports Global and accepts some specific attribute as well which are listed below.

Attribute Value Description
href URL Specifies the URL of a page or the name of the anchor that the link goes to.
target _blank
_parent
_self
_top
Where to open the target URL.

Examples of HTML base Tag

Bellow examples will illustrate the usage of base tag. Where, when and how to use base tag to speficify base URL.

Specifying a default URL

Following is a basic example of the usage of the <base> tag.

<!DOCTYPE html>
<html>

<head>
    <title>HTML base Tag</title>
    <base href="https://www.tutorialspoint.com" />
</head>

<body>
    <img src="/cg/images/logo.png" />
</body>

</html>

Default target for all links

Let’s look at the following example, where we are going to set the default target for all the URLs on the page.

<!DOCTYPE html>
<html>

<head>
    <base href="https://www.tutorialspoint.com/index.htm">
</head>

<body>
    <p>
        <a href="/html/index.htm">
        <img src="/cg/images/logo.png" 
             height="39"
             alt="logo"> 
        </a>
        <br> 
        Tutorials Point originated from the idea that
        there exists a class of readers who respond 
        better to online content and prefer to learn new
        skills at their own pace from the comforts of their
        drawing rooms.
    </p>
</body>

</html>

Base URL for multiple relative links

Consider another scenario where we are going to take the base URL, which all the relative links treat as the starting URL and opens in the same window.

<!DOCTYPE html>
<html>
<head>
   <title>HTML base Tag</title>
   <base href="https://www.tutorialspoint.com/index.htm">
</head>
<body >
   <h2>List of Tutorials</h2>
<ul>
   <li><a href="/html/index.htm">HTML Tutorial</a></li>
   <li><a href="/css/index.htm">CSS Tutorial</a></li>
   </ul>
</body>
</html>

Supported Browsers

Tag Chrome Edge Firefox Safari Opera
base Yes Yes Yes Yes Yes
html_tags_reference.htm
Advertisements