08/09/2011

HTML Base Tag

by Cyle
Categories: Web Development
Tags: , ,
Comments: Leave a Comment

The base tag in HTML is used to define the base or anchor of links and addresses on a web page. The base tag can be very beneficial, but can also cause many headaches. Check out the example below to get an idea of how to use it.

Example

Lets say I am located at http://www.cconoly.com/blog/ and below is a link on this page.

<a href="test.html">Click here</a>


This links to http://www.cconoly.com/blog/test.html.
Now when you add the base tag:

<base href="http://www.anypage.com/" />
<a href="test.html">Click here</a>

It leads to http://www.anypage.com/test.html.

 
Like I said, it can be very helpful or a major problem. If you download a page from the web to your hard drive, sometimes you will need to add a base to the links so that they are looking to the web and not looking on your hard drive for the links. This is exactly what the base tag should be used for. Sometimes it will be used on a web site that is pulling its images from elsewhere and you want to use the base tag so you do not have to include a long address for each image. However, if there is a link somewhere else on that page that was expecting the base to be different then you will have problems. It is a real head ache when you need to come back to your page months or even a year later and forgot that the base tag was added. You will be looking everywhere trying to figure out why none of your links or images work. If you do use the base tag, I would recommend using it at the beginning of your code and maybe even comment a section above explaining why and how you used it.


Leave a Reply

Your email address will not be published. Required fields are marked *



user-avatar
Today is Wednesday
04/26/2017