Geeks With Blogs
Ilya Verbitskiy Thoughts and links about computer programming


I have an interesting call this morning. One of our customers copy-pasted an email from his email client to our CMS. All links on the page were screwed up, all links on the page had been pointed out to a web-site. The cause of the problem was simple. Email client added the <base> tag to the page to force all links in the email to point out to a third party web-site. It was the first time I had heard about <base> tag.

The <base> tag is used to specify the base URL to use for all relative URLs contained within a page. It means you can use absolute URLs to avoid the issue I had. The tag has two attributes:

  • href. The base URL to be used throughout the document for relative URL addresses.

  • target. A name or keyword indicating the default location to display the result when hyperlinks or forms cause navigation, for elements that do not have an explicit target reference.

You may find very good <base> tag definition on Mozilla Developer Network.

Let’s see two use cases. First of all, I will use the <base> tag without target attribute.

   1:  <!DOCTYPE html>
   2:  <html>
   3:      <base href="" />
   4:      <ul>
   5:          <li><a href="2013/01/22/wpf-how-to-find-control-location.aspx">WPF: How to Find Control Location.</a></li>
   6:          <li><a href="2012/11/10/wpf-timers.aspx">WPF: Timers.</a></li>
   7:      </ul>
   8:  </html>

All links on the page are pointed to You will open then in the same browser window.

Now let’s try to use target _blank.

   1:  <base href="" target="_blank" />

Now you can see the differences. Links pop up in new window.

There is an obvious question. Should I use this tag? There is an obvious answer to this question. It depends… Personally, I would try to avoid using this tag, because it may overcomplicate page maintenance: all relative links will be pointed out to one absolute location. Usually the latest think what a developer will do, when he sees the bug mentioned above,  is to look for a <base> tag. From the other side, <base> tag might be useful in page templates. You can set the base page location and simplify the rest of links in your template. There are pros and cons, and it is up to you either you will use it or not.

Posted on Sunday, April 21, 2013 5:59 PM Web Development | Back to top

Comments on this post: Using the <base> tag

# re: Using the <base> tag
Requesting Gravatar...
Thanks for your post, i like this<br>spesifikasi dan harga komputer
Left by rachmadp24 on Jan 14, 2014 5:25 AM

# re: Using the <base> tag
Requesting Gravatar...

The article posted was very informative and useful

Left by jaring safety on Oct 11, 2014 11:23 PM

# Active Sports Nutrition
Requesting Gravatar...
I'm very impressed from this blog because there are a lot of informative postings... Active Sports Nutrition

Left by Jackson John on Feb 23, 2015 10:59 PM

Your comment:
 (will show your gravatar)

Copyright © Ilya Verbitskiy | Powered by: