Warning:
This wiki has been archived and is now read-only.

Elements/base

From HTML Wiki
Jump to: navigation, search

<base>

The <base> element allows authors to specify the document base URL for the purposes of resolving relative URLs, and the name of the default browsing context for the purposes of following hyperlinks. The element does not represent any content beyond this information.

Point

  • A base element must have either an href attribute, a target attribute, or both.
  • There must be no more than one base element per document.


HTML Attributes

  • href = valid URL potentially surrounded by spaces
    A base element, if it has an href attribute, must come before any other elements in the tree that have attributes defined as taking URLs, except the html element (its manifest attribute isn't affected by base elements). [Example A]
  • target = valid browsing context name or keyword ( _blank, _self, _parent, or _top)
    The value of the target attribute is used as the default when hyperlinks and forms in the Document cause navigation.

See also global attributes.

Examples

Example A

In this example, a base element is used to set the document base URL.
The link in the above example would be a link to "http://www.example.com/news/archives.html" [try it]:

<!DOCTYPE html>
<html>
    <head>
        <title>This is an example for the <base> element</title>
        <base href="http://www.example.com/news/index.html">
    </head>
    <body>
        <p>Visit the <a href="archives.html">archives</a>.</p>
    </body>
</html>


HTML Reference

The HTML5 specification defines the <base> element in 4.2.3 The base element.