HTML <base> tag
The <base> tag is used to set a base URL for all the links on a page.
NOTE: The <base> tag has no closing tag and must go inside the head section of an HTML document.
Attributes
| Attribute | Possible values | Description |
|---|---|---|
| href | baseURL | Specfies the base URL for all the links on a page |
| target | _blank for new window, _self for same frame, _parent for parent frameset, _top for full body of the window | Specifies where to open all the links on a page |
Standard attributes
NONE
For more information on standard attributes, check out our HTML standard attributes reference page.
Event attributes
NONE
For more information on event attributes, check out our HTML event attributes reference page.
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:
Now whenever you need to display an image on your page, you can do so by specifying 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/.
Tips & notes
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.