HTML base tag

Html <base> tag specifies the alternate or default URL (address) for all the hyperlinks present in a page. This default URL is written in the href attribute of the <base> element.

Example

<!DOCTYPE html>
<html>
<head>
 <base href="https://www.google.com" target="_blank">
</head>
<body>
 <p>We have not given any address but the default address is in the href     attribute of base tag.</p>
 <a href="">Browser</a><br>
 <a href="">Search</a>
</body>
</html>
Try </>

Only one element should be used only once in a page.

If there are more than one base elements then all the base elements are ignored except the first one.

If there are more than elements with different target attributes then all are ignored except first one.

Tag omission

the base is self-closing element (</base>) i.e. there is no end tag.

Global Attributes

All global attributes are applicable on the base element.

Specific Attributes

href attribute

The value of this attribute is a valid URL. There are four different values for the href attribute.

<base> tag attributes

AttributesDescription
href href attribute defines the location of the external resource.
<base href="URL" target="_blank">

target attribute

There are four browsing modes.

target='_self':

The default value of the target is '_self'. It means the link opens in the current window.

<base href="http://www.codingb.com" target="_self" />

target='_blank':

This attribute opens the linked source in new window.

<base href="http://www.codingb.com" target="_blank" />

target='_parent':

It opens the linked source in the parent block(window) of the current block or window.

<base href="http://www.codingb.com" target="_parent" />

if the parent is not present then link opens in current window.

target='_top':

If the link is present in nested frames then the link opens in the top most browsing context (frame).

<base href="http://www.codingb.com" target="_parent" />

If there is no top target frame, then link opens in the same window(frame).

Visit target attribute for more information.



Was this article helpful?

 

Email:

Message:

Get the newsletter