Learning Resources

base tag

The HTML base tag allows you to specify a default address or target for all links on a web page. It can be quite useful at times.

One use is to have all the links on a page open in a new window—although nowadays that could also mean the links open in a new tab, it just depends on how a person has their browser preferences set.

To have all links open in a new window (or tab) add the follow code to the HEAD section of your page:

There is no closing tag. Another way to use the base tag is to point to your website root, like this:

I use that on my 404 page. A 404 page is an error page. When your browser tries to connect to a page that isn't there, most web servers will show the 404 error page instead (if there is one).

When the missing page is in another directory, the 404 page will show up minus the images, and other external files, such as an external style sheet, won't be called into action either . . . unless you include the base tag with a link to your website's root directory.

With the base website address in place, all your links and references to external files will work no matter which directory the 404 page is being called from—and happy days are here again!

Note that the base tag should be placed in the HEAD section of your page, before any references to other external files.