I am reading and taking notes on the HTML specifications for 100 days as part of #The100DayProject. Read the initial intent/backstory. I am a Microsoft employee but all opinions, comments, etc on this site are my own. I do not speak on behalf of my employer, and thus no comments should be taken as representative of Microsoft’s official opinion of the spec. Subsections not listed below were read without comment.
Currently reading in 4.2 Document metadata
4.2.3 The base element
“The base element allows authors to specify the document base URL for the purposes of resolving relative URLs, and the name of the default browsing context for the purposes of following hyperlinks.”
There should only be one
base element (all but the first will be ignored), which has no content, but rather an
href and/or a
This element should precede all others that have URL attributes, as you’re basically setting the default domain for URL resolution. The only exception is the
html element; whatever is set in the
base element doesn’t bubble up to the root element.
Here’s where you can kind of be evil with HTML alone: you could set the browsing context to be
_blank, which would be an absolute nightmare for sites with a lot of internal URLs.
I’m trying to think of a case in which you’d want to set the base URL in this manner. Most of the time it would be redundant; you probably want relative URLs to resolve on the same domain that you’re already on. Ideas:
- If all your relative URLs will have/a/really/long/standard/structure and you want to save yourself some writing/bytes in the markup.
- You have both v1.0 and v2.0 of a website live and are incrementally bringing people over to the new site. You want to preserve the old version of a particular page (for now) but want the relative links off this page to resolve to the new version without requiring a redirect (which are not fun for perceived performance).
- You want to point relative links to a localhost URL when the site is opened from a file navigator.
I don’t know, this element seems like it would help you be lazy—er, efficient—but it seems it could easily be more trouble than it’s worth. It’s easy to forget what you can’t see, and so if you’re not diligent is checking links, you might direct traffic to broken pages or outdated destinations.