HTML
HTML introduction
HTML basics
HTML text format 1
HTML text format 2
HTML text format 3
HTML links
HTML images
HTML image maps
HTML forms
Fieldset/legend tags
Email links
HTML labels
HTML tables
HTML frames
HTML backgrounds
HTML colors
HTML color shades
HTML color usage
HTML marquees
HTML fonts
HTML entities
HTML stylesheets
HTML layout
HTML div/span
HTML audio
HTML video
HTML objects
HTML d'load media
HTML meta tags
HTML scripts
HTML declarations
HTML head section
HTML document types
HTML tag rules
HTML things to avoid
URL formatting
Encoding and decoding
HTML use/access
HTML publish work
History of HTML
HTML summary

Programming

Programming intro
Java

Markup

First webpage guide
XHTML

Style & Layout

CSS

Browser scripting

Javascript
VBScript
AJAX

Server scripting

PHP
ASP

Making money online

Make money online

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

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.

See more base tag examples

Practice

Online code editor
Practical examples
Practical exercises
Step-by-step tutorials

Reference

Terms glossary
Reference material

Rate this site

Rate this site
Visitor comments