xml:base is an XML attribute. When set on an element, it overrides the base URI of that element and its child nodes in the DOM.

The base URI is used to resolve relative URIs when needed. In XML context, XLink and XInclude rely on this. For example in the snippet below the URI xlink:href="pick1.xml" points to is affected by the xml:base attribute on the parent olist element:

<!-- ... -->
<olist xml:base="/hotpicks/">
    <link xlink:type="simple" xlink:href="pick1.xml">Hot Pick #1</link>
<!-- ... -->

The algorithm used to compute the base URI is described in the XML base specification (see below).

The computed base URI for any Node can be obtained using DOM property Node.baseURI.

xml:base and HTML

The <base> element in HTML can be used to override the base URI of the document.

HTML doesn't have a syntax to specify a base URIs for a document subtree, although it's possible to use xml:base in XHTML documents or even
setAttributeNS("http://www.w3.org/XML/1998/namespace", "base", baseURI) in text/html documents with supporting browsers (like Gecko). In this case the value of Node.baseURI may be affected by both the document's base URI (modified with <base>) and the xml:base attributes.


See also

  • xml:base support in old browsers is a pure JavaScript implementation that can be used to compute the base URI of a node based on xml:base information and resolve relative links against it.

Document Tags and Contributors

Contributors to this page: Nickolay, Brettz9
Last updated by: Nickolay,