Anne van Kesteren

Base URI examples

Two days ago we mentioned base URIs. I wonder when I will start using IRI in a consistent matter. Today I will provide some examples and tell you what the resulted location is. Note that this is only true for retrieval actions. Things like <form action=""> are treated differently. Assume I have a XHTML plus xml:base profile, all elements in this post are in the namespace, unless stated otherwise.

Both links are same document references, regardless where the document in question is stored. The rules for this are quite simple. Resolve all URIs against the base URI. When, after removing the fragment identifier from both, and optionally normalizing both, the base URI is the same as the URI that was resolved against it are the same, the URI is a same-document reference. So in the above example does not really point to that location, it points an element with an attribute of type ID with the value foo in the current document, where ever that may be.

Now the base rules are explained, here are some more examples:

This points to

Both examples point to the document they are used in. They do not point to unless the document was really hosted at

Depends if URIs are normalized. If they are not normalized the link points to If URIs are normalized it points to the document it was used in. Fun! In practice normalization almost never happens as it is insanely complicated.

This is a same-document reference. Fragment identifiers have to be removed from both the base URI and the URIs that are resolved against it.

Many thanks to Sjoerd for helping out. Next time we might address more than just retrieval. I should probably mention that web browsers do not follow this, defined in internet standard 66. Parts are incompatible with the web. I should also mention that this applies to the base element as well. Obviously.


  1. So the xml:base attribute is more important to resolving URI's than the current, real location?

    Posted by Mark Wubben at

  2. They do not point to unless the document was really hosted at

    (This is a same-document blockquote. There's no ID for the content.)

    Point to is really sloppy wording. The 2 examples do not retrieve the resource at, but they do resolve to Where they are hosted is irrelevant.

    Parts are incompatible with the web.

    Are you sure? RFC 2396 was incompatible with the web, so most browsers still relied on RFC 1808. I thought RFC 3986 was meant to fix these problems (amongst other things).

    So the xml:base attribute is more important to resolving URI's than the current, real location?

    xml:base attributes, and html:base elements, are meant as real location replacements.

    Posted by Sjoerd Visscher at

  3. *holding head* What? I thought I understood all this. Anne, any chance of an English translation? The base attribute and element should point to the source document yeah? The original document the elements are from? Or maybe the document you're currently viewing?


    Posted by hemebond at

  4. To be more specific: the href DOM property will return http:// or http:// in all examples. If the base URI is http:// then clicking on the links will let the browser scroll to the top of the page or to #foo. If the base URI is something else, then the browser wil navigate to http://

    Posted by Sjoerd Visscher at

  5. So the way I use it (and see it being used on the live web) is wrong then? Do I understand that right or am I just being thick?

    I.e. I use it as the URI where the index page of the site can be found, and to which relative URIs should be resolved.

    Posted by Ben at

  6. Yes. With a conforming browser, the links on your site to your homepage would be a same-document reference, and the only effect clicking it would have is to scroll to the top of the page.

    Posted by Sjoerd Visscher at

  7. So, to take the example of Ben’s site, the menu section (id="nav") should have a base URI that is something like:

    (whether or not the menu is really present at that URI doesn’t really matter) ??? It does correspond to the ‘the menu is (semi-)included content’ line of thinking...

    Phooey, trying to understand this properly seems to be quite brain-wrecking ;p.


    Posted by Laurens Holst at