Posts Tagged ‘HTML base tag support’

HTML base tag


Description:

The <base> tag specifies the base URL/target for all relative URLs in a document.

The HTML base tag sets the base URI that will act as starting point for all relative URIs present in the document. When absent, the base URI is the URI of the folder containing the document. This element must be inserted somewhere in the head of the document .

There can be at maximum one <base> element in a document, and it must be inside the <head> element.

Tip: Put the <base> tag as the first element inside the <head> element, so that other elements in the head section uses the information from the <base> element.

Note: If the <base> tag is present, it must have either an href attribute or a target attribute, or both.

Difference between HTML and XHTML:

In HTML the <base> tag has no end tag.

In XHTML the <base> tag must be properly closed.

Difference between HTML 4.01 and HTML5:

None

Example:

Assume that the absolute address for an image is:

<img src="http://www.mytoptutorials.com/images/html.gif" />

Now we insert the <base> tag, which specifies a base URL for all of the links in a page as follows:

This will produce following result:

<head>
    <base href="http://www.mytoptutorials.com" />
</head>

Now you do not need to use complete path of the image. You can insert above image as follows:

<img src="/images/html.gif" />

Attributes:

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.

  • _blank – the target URL will open in a new window
  • _self – the target URL will open in the same frame as it was clicked
  • _parent – the target URL will open in the parent frameset
  • _top – the target URL will open in the full body of the window
Designed for Mytoptutorials.com