Deprecated
This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

xml:base is like the HTML <base> element, but can specify the base URI per element as well as the entire document.

The base URL of a element can be queried from a script using Node.baseURI.

The base URI of an element is:

  1. the base URI specified by an xml:base attribute on the element, if one exists, otherwise
  2. the base URI of the element's parent element within the document entity or external entity, if one exists, otherwise
  3. the base URI of the document entity or external entity containing the element.

Support was removed from blink (Chrome and Opera) in 2015:

And from Firefox 66 in bug 903372.

Use cases

If you have an inline SVG you use as icons that needs to work in a document with a HTML BaseElement , you can reset the URI on your icon sprite by setting the xml:base.

<html>
  <head>
  <base href="https://mydomain.com">
  <style>
  .link { stroke: #999; stroke-opacity: .6; }
  marker#arrow { fill: black; }
  </style>
</head>
<body>
  <svg width="100%" height="100%" xml:base="">
    <defs>
      <marker id="arrow" viewBox="0 -5 10 10" refX="0" refY="0" markerWidth="20" markerHeight="20" orient="auto">
        <path d="M0,-5L10,0L0,5"></path>
      </marker>
    </defs>
    <line x1="100" y1="100" x2="333" y2="333" marker-start="url(#arrow)" class="link"></line>
  </svg>
</body>
</html>

Imagine a SVG with font references. E.g.

<svg xml:base="https://foobar.s3-eu-west-1.amazonaws.com/uploads/15066845653629"
  width="909" height="1286" viewBox="0 0 909 1286"xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<style type="text/css"><![CDATA[

.s9_999{
font-size: 9.17px;
font-family: ZapfDingbats_ghr;
fill: #161615;
}
]]></style>

  <text
    x="647"
    y="412"
    dx="0"
    class="s9_999"
  >r</text>

<style type="text/css"><![CDATA[

@font-face {
    font-family: ZapfDingbats_ghr;
    src: url("fonts/ZapfDingbats_ghr.woff") format("woff");
}

]]></style>

</svg>

Setting the xml:base on the SVG Element means you can inline the SVG and thereby bypass CORS issue while not changing the base URI for your entire document.

Work-arounds

Specifications

Specification Status Comment
XML Base (Second Edition) Recommendation

Browser compatibility

No compatibility data found. Please contribute data for "xml.attributes.base" (depth: 1) to the MDN compatibility data repository.

Document Tags and Contributors

Last updated by: bershanskiy,