<base> HTML Tag

Element of
Anchors and Links
What does <base> HTML Tag do?
The <base> element is used to identify a base URL upon which to build all relative URLs that appear on a webpage. In addition, if the <base> element has a target attribute, the target attribute will be used as the default attribute for all hyperlinks appearing in the document.
Null element
This element must not contain any content, and does not need a closing tag.

Example Code

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

Relative links

When creating an anchor link, the href attribute can specify an absolute URL, like http://example.com, or a relative URL such as /, /page-name, or page-name.

With relative URLs a slash ( / ) indicates the root URL of the current page, so href="/page-name" would link to a page at currentdomain/page-name. Leaving off the slash links to a subpage of the current URL, so href="page-name" would link to current_url/page-name.

Using the <base> element, you can change the base URL which the relative links on the page use. Instead of the current, actual URL of the current page, all relative links will be based on the URL specified in the href attribute of the <base> element.

For more information about how relative links work, see our documentation on anchor link urls.

Default target value

In addition to specifying a base URL for relative links, the <base> element allows you to specify a default target value for all links on the page. So, if you set target="_blank" in the <base> element, all links on the page (relative and absolute) will open in a new window, unless otherwise specified.

Placement and restrictions

The <base> element must be placed within the document’s <head>, and there must only be one <base> element in a document. The <base> element must not have any content, and does not require a closing tag.

Adam is a technical writer who specializes in developer documentation and tutorials.

Browser Support for base