xml:base is like the HTML BaseElement 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.

Unfortunately, support was removed from blink (Chrome and Opera) in 2015.

  1. https://bugs.chromium.org/p/chromium/issues/detail?id=341854
  2. https://groups.google.com/a/chromium.org/forum/#!topic/blink-dev/ZvArHAXyAHM

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.


  <base href="https://mydomain.com">
  .link { stroke: #999; stroke-opacity: .6; }
  marker#arrow { fill: black; }
  <svg width="100%" height="100%" xml:base="">
      <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>
    <line x1="100" y1="100" x2="333" y2="333" marker-start="url(#arrow)" class="link"></line>



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">
<style type="text/css"><![CDATA[

font-size: 9.17px;
font-family: ZapfDingbats_ghr;
fill: #161615;


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

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



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.






Document Tags and Contributors

 Contributors to this page: dotnetCarpenter
 Last updated by: dotnetCarpenter,