All your <base> are belong to us


For IE 7 we decided to make some changes to the way the <BASE> tag is handled to bring it up to spec and at the same time fix some really odd behavior. In the process we expect some people relying on the previous behavior to have to update their content otherwise they may find their site doesn’t work exactly as planned. Most of the old functionality is still there, but there are some key differences.

To start, in previous versions of IE, you could place the BASE tag anywhere in the document. This behavior isn’t per the specification even as far back as HTML 3.2 which specifies there should only be one BASE tag per document and that the BASE tag should appear in the HEAD element. Because we allowed the BASE tag to appear anywhere it allowed you to BASE different portions of your document to different locations. Now with IE 7 we’ll be ignoring any BASE tags that appear inside of the BODY tag and we’ll only obey the first BASE tag that appears in the HEAD element. For pages that used the old behavior they may now have broken image links or anchors that don’t navigate to the proper locations. The workaround is to move the BASE tag into the HEAD tag and only have one BASE per document per the HTML 3.2 and later specifications.

The BASE element in older versions of IE was also a container element. In order to support multiple BASE elements per page and have them affect any elements following them in the tree they become descendants of the BASE element. When we need to look up and create an URL for either a link, anchor or area element we simply walk the parent chain until we find the first BASE element. This was a great shortcut, but it does have some problems. First the BASE element is now considered in CSS matching rules. So if you have any BASE elements in your document then at some point you may have to include them in your selectors for them to properly match. This would mean making special IE only rules which aren’t compliant and wouldn’t match in other browsers. Another side effect is that the BASE element when defined in the HEAD element would end up being the container for the BODY tag. This would break common rules using the child selector (>) from CSS 2.1 since HTML > BODY would simply fail to match because the document tree would contain a BASE tag between the HTML and the BODY tags. In IE 7 the BASE element no longer contains any other elements so you don’t have to worry about including it in CSS rules and it won’t show up as an element in the document tree between the HTML and BODY.

What this means for IE 7 is that we are more compliant to the HTML specifications. It also means being more compliant in the areas of CSS and selectors. And finally it means you can more reliably walk the DOM to get the information you need without having to worry about looking under BASE tags for nested child elements. In previous versions of IE the placement of the BASE tag might mean that a quick scan of all of the direct children of the HEAD element would come up a few elements short if those elements followed the BASE tag.

Supporting the new IE 7 behavior should be really simple as long as you weren’t previously relying on the use of multiple BASE tags. Basically, you’ll want to make sure any BASE tags you have appear within the HEAD element and not inside of the BODY or as part of a bare document that doesn’t contain a HEAD element. Try to include only one such tag since behavior within IE when searching for the BASE tag is only going to look for one of them. If you have more than one, then you might not get the desired behavior. If you previously wrote any CSS selectors or DOM walking code that accounted for the BASE tag you’ll find you don’t need to do that anymore and you can remove those extra rules and code (or just leave them in, they won’t match)!

– Justin Rogers

Resources:
HTML 3.2 Specification for the HEAD element and its children
Sample HTML files with DOM trees for both Pre IE 7 and the new IE 7 behavior

Comments (67)

  1. Anonymous says:

    At least we’re getting closer towards full compliance. Albeit slowly but surely, but better late than never?

  2. Anonymous says:

    Well, I guess compliance starts somewhere.

    But surely compliance with modern specifications, such as XHTML1.1 should come before older specifications, like HTML3.2

    Unless, of course, the things that aren’t implemented properly in HTML3.2 are blocking XHTML1.1 compliance. But refresh my memory, is the <base /> element even in XHTML1.1?

  3. Anonymous says:

    Most ironic title for a blog entry ever.

    Glad to see something’s being done anyway.

  4. Rosyna says:

    YAY! this is good happy fun time!

    this is exactly how IE 7 should be handled. Even if it does break existing sites, it makes IE behave exactly how it should. To better prepare for the future, you must sometimes sacrifice the past, Buffy.

  5. Anonymous says:

    You know, I never looked at the spec for BASE, but I assumed it worked this way.

    You’ve simplified it, and told anyone doing daft craziness that it won’t work in future. Good stuff.

    I hope this goes further – and dare anyone to admit this has broken their site. πŸ™‚

  6. Anonymous says:

    You have no chance to survive,

    make your time

    HA HA HA!

    (Couldn’t resist)

    In all seriousness, I can imagine phishing attempts on site messageboards would be possible by overriding the base tag within the document itself.

    Good work.

  7. Anonymous says:

    Hooray for compliance fixes πŸ™‚ Thanks guys.

  8. PatriotB says:

    Thanks Justin for an informative, detailed post. Let’s hope there are more posts forthcoming of a similar nature regarding changes to IE’s HTML handling.

  9. Maurits says:

    "This would break common rules using the child selector (>) from CSS 2.1"

    Whoa… does this mean IE 7 will support the CSS 2.1 child selector??

    SWEET!!

  10. Anonymous says:

    Nice to see Microsoft IE developers turning to standards. Compliant websites are starting to recommend browsers other than IE because of their lacking in that area. At least now they might put a message saying: "Best viewed with Firefox or IE 7" instead of "Best viewed with anything but IE"

    Microsoft is always hit very hard for having a bad rep for insecurity and manipulating things to go their way only. Maybe Windows Vista and IE 7 can change this, but it’s hard for me to get "excited" about the future. Articles like this at least make me feel like things might change, but it’s more of a "see before I believe thing".

    Keep up the good work πŸ™‚

  11. Anonymous says:

    GOOD WORK

    ———

    Xcellent.

    Logical.

    Reasoned.

    Compatible.

    –and this is Microsoft! Alright!!

  12. Anonymous says:

    Funny. IE 6 or below doesn’t support child selector, right?

  13. Anonymous says:

    A couple of nitpicks:

    > To start, in previous versions of IE, you could place the BASE tag anywhere in the document. This behavior isn’t per the specification even as far back as HTML 3.2

    Actually, it goes back to HTML 2.0.

    Also, everywhere you write "BASE tag", you mean "BASE element type". A tag is merely the syntactical marker that begins and ends elements.

    Are we going to get a weblog entry that discusses whether or not the "* html" CSS hack is going to be included in Internet Explorer 7?

  14. Anonymous says:

    "Basically, you’ll want to make sure any BASE tags you have appear within the HEAD element and not inside of the BODY or as part of a bare document that doesn’t contain a HEAD element."

    That isn’t standards compliant. HTML allows documents that don’t contain "html", "head", and "body", but those elements still are present in the DOM. Look at this HTML:

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">

    <title>A valid document</title>

    <base href="http://www.w3.org"&gt;

    <p>This document is valid!

    Firefox, Amaya, and the W3C Validator’s "Show Parse Tree" option have something like this in the DOM:

    html

    -head

    |-title

    -|-A valid document

    |-base

    -body

    |-p

    -|-This document is valid!

  15. Anonymous says:

    The IEBlog has just posted an&amp;nbsp;entry about the behaviour of the BASE tag in IE7. The standard (back…

  16. Anonymous says:

    Fantastic! I’ve never used the BASE element myself, but the news that you will strictly adhere to standards with no compromise ("just update your websites, dammit!") is great news.

    I hope that this trend goes a bit further and helps to stamp out lazy web developers who write tcode that just barely looks right in "forgiving" browsers, but wouldn’t stand a snowball’s-chance-in-hell of passing even a transitional validation test.

  17. Anonymous says:

    My great hope for IE7 was that it would conform to W3C’s standards. After all, Mozilla, Opera, Firefox and most others do. But despite this, I have found that things like spacing and font sizes, defined in the style sheet are still enlargened on IE7.

    Furthermore, when doing a quite complex 3-column solution using css (no tables!), for example, the column on the left is wider in some places than others, instead of the centre content leaving the required space at the left side for the content beside it, it clears all of the left hand side, regardless of whether the longer left content is further down the page.

    Since IE7 is only in the beta stage, I hope this is something that will be fixed at a later stage.

    If IE7 can conform to the standards set by W3C, it would be doing itself, and web developers a massive favour.

    Without conforming to these standards, Microsoft is penalising those who wish to implement professional looking web sites, which are also WAI compliant.

  18. Anonymous says:

    I was waiting for IE with tabs 4 like 6 months and its really great!!!

    Everything is well and good but why have you dis-arranged the menu-bar, tab-bar, address-bar like that?

    And the worst part is it cannot be changed!

    the usual way wud naturally b that menu bar stays on top.

    Other features of IE7 r cool! GREAT WORK!!!

  19. Anonymous says:

    It’s not a big step, but it is the correct attitude!!! Every IE feature that deviates from the spec is just another compatibility nightmare for web developers.

    Little things like this (so long as there are lots of little things like this fixed) will please me greatly when it comes to making web apps and web sites.

  20. Anonymous says:

    Did you also fix the bug with same-document references (f.e. "#somewhere") together with a base element?

    See f.e. Google cache results:

    http://66.102.9.104/search?q=cache:xuTmYd9HCSMJ:www.w3.org/TR/REC-html40/struct/links.html&hl=en

    The links in the toc should stay in the current document (the cached document), they should not jump to the original document.

    See RFC 3986, section 4.4.

    http://www.gbiv.com/protocols/uri/rfc/rfc3986.html#same-document

  21. Anonymous says:

    Thanks a lot Justin, this kind of precise, feature by feature, fix by fix, implementation by implementation blog posts was exactly what I was looking forward to seeing on this blog.

    Thanks.

    A lot.

    Please, don’t hesitate to do that more often

    > Whoa… does this mean IE 7 will support the CSS 2.1 child selector??

    > SWEET!!

    Yes, it’s been stated in the IE7b2 feature list that IE7 would implement full CSS2.1 selectors support.

  22. Anonymous says:

    Why the odd changes to the IE user interface and toolbars? I really like having forward/back/stop/refresh as regular buttons in the "Standard Buttons" toolbar. I also place my address bar next to the menu right after "Help" which has been a nice placement and saved vertical space.

    Now there’s the forced combination back/forward/address bar pinned to the top of the window ABOVE the menu. Very disappointing. Keep at least the level of configuration that IE 6.0 has. Or at least let me turn it off via the options. I think it’s ok to have the stop/refresh combined, but the rest is not good.

    Awful, awful, awful.

    Also, please fix CSS. There’s really no excuse for the lingering defects.

  23. Anonymous says:

    Grant Wohl – Grant, there are times where we’ll imply a HEAD element, you are correct. The document tree for what you mentioned would see the TITLE element and then imply a HEAD element parent. The following tags, so long as they are valid in the HEAD element would also appear in the HEAD element. The moment you have a tag that implies the BODY element though the BASE element will end up in the wrong spot. There might be more we can do here in the future and I’ll definitely look into that.

  24. Xepol says:

    ya, great. Now MS is making it even harder to develop pages. By deciding to leave 98 and W2K out of the IE 7 cycle, we will even up with not just a fork between MS and NS and Opera, but now MS will fork internally.

    Great, now we all have to code for TWO different MS variants. Thanks.

    Its about time that MS admits the truth. IE is NOT an OS-tied component. Yes, the OS may require IE’s active X browser for explorer views, but IE does NOT require a particular OS (and when it does for extra graphics calls, they can be back ported easily enough).

    Sadly, MS doesn’t want to admit that IE 7 could easily run on win98 because that would harm their assertion that XP couldn’t run without it. Now, obviously that logic is nonsense, but its the mind set. (it is not a bidirectional relationship after all, just one way, xp needs IE, but just barely).

    Now don’t get me wrong, I like apps that use IE’s browser control, and I think its great that it is available like that (but the control is so freaking flakey to use that most people never used it for long or to do more than to view an simple HTML doc), however, using logic like that to NOT support your customers is just plain stupid. MS wants to create an industry standard, but ignores its own customers while developing it just because they haven’t upgraded to the latest OS.

    You are seriously making our lives more difficult here. The easiest solution would be for IE 7 to run on the older platforms (right back to win95 would actually be best – I have a 95 box in my network, because MS stopped supporting FUTURE versions of the OS for some MS hardware that I use)

  25. Anonymous says:

    It’s nice to read this, shows that Microsoft even pays attention to less-used features such as <base> :). Although you were probably forced to fix this because you were implementing the child selector, I think it shows promise for the kind of bugs / non-standard behaviours that you are fixing in IE, and that you are not afraid to break things when doing so. I’m eagerly awaiting Beta 2!

    "Funny. IE 6 or below doesn’t support child selector, right?"

    No, and that is exactly why the old behaviour wasn’t a problem up till now :).

    ~Grauw

  26. Anonymous says:

    Xepol, you really are a one tune kind of guy, aren’t you? *yawn*

    Do you think Microsoft is suddenly going to offer IE7 on 98 just because you whine about it in every post here?

    The beta 1 is out. There will be a beta 2 at some point. They aren’t going to go develop IE7 for unsupported operating systems now. Heck, you can’t even make 95, 98, or ME secure because they are DOS based.

  27. Anonymous says:

    I think it is important to note that certain fixes, like that of the BASE element and the types of object model trees it was responsible for forming, aren’t just in place to support certain features.

    The previous behavior of the BASE element was actually in place for a specific reason. So that we could support multiple BASE elements on the page. Yes, this wasn’t spec’ed behavior, but it was a behavior that was prominent on the web.

    Primarily due to the object model tree not being properly formed because of this we decided to change the BASE element implementation. It just so happens that it also fixed some odd behaviors I was seeing while implementing CSS 2.1 child selectors.

    Isn’t that neat? You have way more insight into the world of IE now.

  28. Anonymous says:

    Justin,

    I echo previous comments that this is the sort of blog post web developers want to read. We know what changes have gone into beta1 and we know what is planned for beta2, but it is a completely different thing reading about planned features and reading about them being implemented.

    As a web designer/developer I don’t like IE and I haven’t for some time now, but I am eager to see what the public beta will hold. Many web designers/developers, myself included, play several roles at one time (graphics, html, css, php/asp, sql). Working around IEs bugs, just wastes time, money and patience. All I want to do when I begin a new project is type in what I know should be there in the correct order, and boom, everything works as expected. If IE7 allows me to do that, I’m in.

    Great positive post, keep them coming.

    Sorry for the rant πŸ™‚

    Cheers;

    Poncho

  29. Anonymous says:

    One more thing:

    I hope Microsoft marketing will make a BIG thing of the IE7 release to push adoption rates up quickly. Specifically I’d like to see IE7 added to Windows Update as a mandatory update for WinXP. Amazingly there is still quite a large installed base of IE5 6.1% of all web users is a lot of people. I would hate to think that we have to support IE6 for more than a couple of years.

    Thanks and good luck to all the IE team members. I understand it’s a long road ahead.

    Cheers;

    Poncho

  30. Anonymous says:

    @Allen

    I agree with you. It was a big advantage of IE to have a completely customizable toolbar layout. I even leveraged this to build my own address bar which could easily replace the standard address bar while adding some features I always wished to have in IE. It would be bad if this flexibility will be lost in the final release of IE 7. At least there should be an option to separately turn off the address and tabs bar.

    @IE team

    Thanks for the insight and detail you give us on certain aspects of IE. I would be glad to read something about the changes made to the IE platform SDK in a future post.

    And one question for your managers: Why is there no easy way to report bugs in MS software? That’s ridiculous.

  31. Anonymous says:

    Just out of interest I thought I’d see what MS’s own site looks like these days, I couldn’t believe it when I tried this!!

    http://validator.w3.org/check?uri=http%3A//www.microsoft.com/

    I am truly shocked!

  32. Anonymous says:

    lol @ seb

    Normal service seems to have resumed on all the pages linked to from http://www.microsoft.com though.

    Just try some from the left-menu… Windows, Office, Win Server and Dev Tools, they all fail to validate – some spectacularly!

  33. Anonymous says:

    <quote>Now with IE 7 we’ll be ignoring any BASE tags that appear inside of the BODY tag and we’ll only obey the first BASE tag that appears in the HEAD element.</quote>

    Can’t we get a warning instead? i don’t mean just on this, but on everything.

    Can we please, please, PLEASE, get an option or mode or setting where IE will tell us everything that is wrong with a page, rather than trying to guess?

    i can imagine a author writing for ie 7, where ie is silently and mysteriously ignoring elements. And it’s not that the author wants his <BASE> in the body, it’s just that ie never says any differently.

    And it’s the same with everything. Internet Explorer is being way too forgiving in parsing web-pages. i WANT to know if there are problems on my web-page. i don’t want ie to have to try to guess what i meant. i don’t want ie silently ignoring elements that are invalid, or mis-placed.

    i want ie to tell me that i tried to close an element when the end-tag is forbidden. i want ie to tell me when border-top is being ignored, because i somehow put ie in standards mode.

    i want a compiler. i want ie to choke on garbage, rather than sifting through it.

    i realize this has to be an option that only developers would turn in, since ie would begin throwing errors for every web-page on the internet.

  34. Anonymous says:

    Hi,

    Sorry about my behavior but i will try again πŸ™‚

    How many time all IE 7 users should wait until a "Pishing Site" appears as "reported" by IE 7 ? I mean, if an user report a site as "Malicious", when all others will see this site reported as "Malicious" by IE 7 ?

  35. Maurits says:

    > Can we please, please, PLEASE, get an option or mode or setting where IE will tell us everything that is wrong with a page, rather than trying to guess?

    Seconded. Call it "Developer Mode" or something.

  36. Anonymous says:

    You say:

    "The workaround is to move the BASE tag into the HEAD tag and only have one BASE per document per the HTML 3.2 and later specifications"

    Surly this should read:

    "The workaround is to fix your website."

    Also, could you stop IE from treating entities without the semicolon as valid, and make the page go green with pink polka-dots if the author includes one? And a spike that pops up out of his chair and stabs him in the ass would be nice too.

  37. Anonymous says:

    @ Seb

    >>Just out of interest I thought I’d see what MS’s own site looks like these days, I couldn’t believe it when I tried this!!

    http://validator.w3.org/check?uri=http%3A//www.microsoft.com/

    I am truly shocked!<<<

    Whats kinda funny is if you try apple.com

    (3 or 4 errors the last time I did)

    better yet try opera.com

    (ditto)

  38. Anonymous says:

    Hmm, http://www.opera.com passes as XHTML 1.0 Strict (an impressive feat!), but then they’ve been busy updating their web page over the last two days, so it may not have when you tried it. Of the 3 errors I see on Apple.com, one’s a gracefully-degrading nonstandard feature, and the other two are easily fixed, but in JS code from another source. Still impressed with http://www.microsoft.com — for a site legendary for browser sniffing and IE-only code to go 100% standards-based is a great move!

  39. Anonymous says:

    @Ian Boyd (and Maurits)

    "i WANT to know if there are problems on my web-page."

    Then run it through a validator. http://validator.w3.org has been mentioned a couple of times in this very thread.

    IE is a browser, not a validator.

    @Justin

    Great post title πŸ™‚ I like the content too. More of the same please…

  40. Anonymous says:

    Let’s not all get too excited about microsoft.com validating. Clicking the big picture in the middle of the page labeled "Choice" takes you to http://www.microsoft.com/windowsxp/evaluation/compare.mspx , which miserably fails validatation: no DOCTYPE, proprietary elements and attributes everywhere, etc. I didn’t test any more page, but obviously they have not built validation or any thought of standards compliance into their content management system; somebody just took a little time to clean up the home page. Yippie. Call me when the other million pages validate, and I’ll be the first to trumpet their efforts.

    As for [base], excellent news. I don’t see any any indication that this is based on DOCTYPE sniffing. Does this change affect all pages, or only pages with a strict DOCTYPE?

  41. Maurits says:

    I’m aware of the validator, thank you. But I want to be able to validate local files too, and I don’t want to wait for a server round-trip, I want the "preview" window to validate.

    The validator is a simple DTD validator… it doesn’t catch things like

    ‘inputs of type="checkbox" require a value attribute’

    because such things cannot be expressed in a DTD. On the other hand, browsers with validation-mode switching can throw a "expected value attribute" exception in the rendering phase.

  42. Anonymous says:

    One of the purposes of releasing the IE7 beta is to collect feedback on compatibility with both websites…

  43. Anonymous says:

    Maurits: I use a built-in HTML validator extension available for my preferred browser. I don’t expect IE would offer similar functionality since this is primarily a consumer-oriented product — a part of the operating system — for the average user, not necessarily the power user. Developers always have the ability to find more specialized tools for our needs.

    Back on topic…

    "Primarily due to the object model tree not being properly formed because of this we decided to change the BASE element implementation. It just so happens that it also fixed some odd behaviors I was seeing while implementing CSS 2.1 child selectors."

    I’m glad to see you guys are going through and cleaning up things like the DOM tree from the ground up.

    As much as I’ll enjoy things like child selectors (and still hope for min/max-width/height!), it’s important that IE7’s CSS 2.1 compliance won’t just be slapping in new features and calling it a day.

  44. Anonymous says:

    > we’ll only obey the first BASE tag that

    > appears in the HEAD element

    IE 7 beta 1 seems to behave differently. I put two base tags in the head, and the second one was used, not the first one.

    <html><head><base href="http://example.com&quot; /> <base href="http://www.microsoft.com&quot; /></head><body><img src="library/toolbar/3.0/images/banners/ms_masthead_ltr.gif"></body></html>

    If the first base tag were used, the image would not load correctly.

  45. Anonymous says:

    As far as I’ve tried, base href in IE6 doesn’t apply to CSS @import and JavaScript window.open (and showModalDialog). Is it going to be fixed? Although I don’t know what the specs say about that, but it looks like a bug. Anyway, it’s good to know that IE7 is moving towards standards compliance… keep it up.