Is the HTML <base> tag also honored by scripting and CSS?

John K picture John K · Jan 29, 2010 · Viewed 12.7k times · Source

The base HTML element provides a base for relative URIs in the HTML. Must JavaScript and CSS also honor it for relative URIs issued in them:

E.g.

JavaScript:

location.href = "mypage.htm"` 

CSS:

h4 { 
    background-image: url(myimage.gif) 
}

(in any browser?)

Answer

Mehrdad Afshari picture Mehrdad Afshari · Jan 29, 2010

CSS paths are always relative to the stylesheet itself and have no dependence on the HTML location (except when IE6 is buggy and stupid and tries to load .htc files specified in CSS behavior attributes relative to the document). For other stuff, <base> will affect the perceived current directory of the HTML as if the file was located in the directory defined by base. Consequently, it does affect things like location.href=...;. By the way, inline styles and style information in <style> element are loaded relative to the document location. Those are affected by the <base> tag, of course.