HTML base tag
There is one tag in HTML which acts as a reference point for all the links on a page. This tag is the <base> tag.
This lesson focuses on:
- The <base> tag
- Is the <base> tag really necessary?
The <base> tag
The <base> tag acts as a reference point for all the links on a page. This reference point is specified with the <base> tag's href attribute.
NOTE: The <base> tag must be placed in the head section of an HTML document. Also, the <base> tag has no end tag.
Example:
Lets say you run the website www.somewebsite.com, and you have a page on this website whose absolute URL is http://www.somewebsite.com/page1.php. On this page, you have seven images displayed and their absolute location is http://www.somewebsite.com/images/. When you try to display these images on your page, you can do so by specifying their location as in <img src="images/img1.jpg" />, <img src="images/img2.jpg" />, and so on, OR you can use the <base> tag to specify a reference point for all the images to simplify displaying them on your page.
The <base> tag to be used in this situation would look like this:
<base href="http://www.somewebsite.com/images" />
Now whenever you need to display an image on your page, you can do so by specifying the name of the image by its name alone, as in <img src="img1.jpg" />, <img src="img2.jpg" />, and so on, and the browser will automatically look for it in http://www.somewebsite.com/images/.
Is the <base> tag really necessary?
There are those who would say that the <base> tag is necessary, and there are those who would say it is not. The <base> tag is efficient in that it makes links work from anywhere. Suppose that someone downloads a page onto their hard drive - without the <base> tag, or without specifying absolute URL's, the link(s) on the page will not work. Essentialy, the <base> tag is used to insure that a link is going to work. While it is not absolutely necessary, the <base> tag makes it possible for links to work from anywhere, and for this reason serves an important purpose in HTML.
Examples
Reference point
This example demonstrates using the base tag to specify a reference point for all the links on a webpage.




