HTML <base/> Tag

 

ATTENTION: THIS PAGE IS Valid HTML 5 AND IS BEST VIEWED WITH HTML 5 - Please upgrade your browser or download one of the HTML 5 compatible browsers such as Mozilla Firefox, Chrome, Opera or IE 9 (March 14, 2011 or later). For more information see HTML 5 browsers.


If you find this helpful, please click the Google +1 Button to the left, if it is white, to make it turn blue or red. Thank you! (It also helps find this page again more easily.)


PDF mobile

The <base/> Tag in HTML 5

The <base/> tag can be used to:

  • specify a base URL for resolving other URLs in the document
  • specify a browsing context for hypertext links in the document, which can be used to open other documents in a separate window, for example

<base/> Tag Syntax

<head>
   <title>Example Only</title>
   <base href="http://www.ExampleOnly.com/articles/" target="_blank"/>
   ...
</head>
Rules for coding the HTML base element

Make sure you understand the difference between a tag and element and are familiar with the definitions of namespace and other HTML terms.

  1. Code a single optional base element in the <head> section of the HTML document where metadata content is expected. It is best to put the <base> tag near the beginning of the head section, since it must come before other HTML tags, such as a <link> tag that may have any attributes with URLs (even if those attributes are not coded, since those attribute values could be added dynamically). The one exception is the <html manifest> attribute, which the base URL does not apply to. The <title> tag and other tags with no URL attributes such as href= can be coded either before or after the <base> tag.
  2. The base element consists of a standalone <base/> tag. The element name uses lower case letters and should be in the HTML namespace, which it will pick up automatically from the xmlns attribute on the <html> tag.
  3. Include at least an href attribute or a target= attribute, possibly both, within the <base> tag.
  4. The value of the href attribute, which is enclosed in double quotes, is the base URL for other URLs in the document, which otherwise would default to the actual location of the document.
  5. The value of the target attribute, enclosed in double quotes, is a name or keyword for the default browsing context for all of the hypertext links in the document. This can be used to open all links in a new window or browser tab, for example.
  6. Include any other HTML attributes on the <base> tag as necessary.
  7. Since the base element is a void element, it should always be coded as a self-closing tag terminated with the delimiter string />.

<base/> Content Model

Contents of the base element

Content: Empty. All properties are coded using attributes.

Since the <base/> tag is a void element, it is not allowed to have any content, even HTML comments and therefore should always be coded as a self-closing standalone tag, ending with the delimiter string /> rather than just > (<base .../>).


<base/> Tag Attributes

Attributes of the <base/> tag
global attributes In addition to the personal attributes of the <base> tag below, any of the common HTML attributes can also be coded.
href

a URI reference that resolves to a URL that will be used to resolve other URI references in the document.

Use percent escape codes as explained in the URL-encoding tutorial for any special characters in the URI reference.

If the value of the href attribute resolves to an HTTP URL, it may contain any of the following components:

  1. protocol scheme, typically http: or else https:
  2. username, followed by an "@"
  3. host name or IP address
  4. port number, which defaults to 80 for the http scheme and 443 for the https scheme
  5. absolute or relative path
  6. search query, indicated by "?"

If the protocol scheme, username, host name/IP address and port number are omitted the default is the current host - the same server as the base of the current document. If the path starts with a slash /..., it is an absolute path from the document root directory (AKA "web root") on the server. A relative path will be resolved relative to the base of the current document.

target target="_self" or target="" (default)
target="_top"
target="_blank"
target="_parent"
target="name"

<base/> Tag Examples

Examples of the base/ tag in HTML 5

Changes in HTML 5 - <base/> Tag

What's new in HTML 5

The target attribute has been added for consistency with the <a> tag.

Differences between HTML 5 and earlier versions of HTML

In previous versions of HTML, the value of the <base href> attribute was required to be an absolute URL. In HTML 5, it can be resolved relative to the address of the document.

In ployglot HTML documents the <base/> tag is coded as a self-closing tag the same as in the 2000-2010 Recommendations from the W3C HTML Working Group. Those specifications changed the ending delimiter to /> from > in older recommendations. They also defined the HTML namespace for the base element type name and the names of other HTML element types.


Valid HTML 5