Base Element Tutorial

<base>

Introductory Text

The base element represents the absolute Uniform Resource Locator (URL) that acts as the base (server) URI for resolving relative URIs used in a document, e.g., “formaldehyde/i-asked-for-water-but-she-gave-me-gasoline.html”.

HTML 4.01 offers In HTML, links and references to external images, applets, form-processing programs, style sheets, etc. are always specified by a URI. Relative URIs are resolved according to a base URI, which may come from a variety of sources. The base element allows authors to specify a document's base URI explicitly.

HTML 5 offers The base element is for specifying a base URL against which relative links will be resolved, and the name of the default target for opening links and form submissions.

If used, the base element must appear in the head section of an HTML document, before any element that refers to an external source. However, in real-world practice it is—Generally—placed at the very end of the head section which may cause difficulties unless all links preceding are absolute URIs, e.g., “http://wwww.sawarkjukejointbox.org/formaldehyde/i-asked-for-water-but-she-gave-me-gasoline.html”.

The base element is considered an empty element; consequently, it does not use an “Open / Close” tag pair, i.e., <[INSERT ELEMENT NAME]></[INSERT ELEMENT NAME]> as all other elements are required to have because empty elements either “generate content” as when <hr> displays a horizontal rule due to the User Agents rendering it; or, when “content” is provided by an external source as seen in the img element.

HTML 4.01 does not require self-closing; whereas, xHTML 1.0 requires an XML self-closing mechanism. HTML 5 allows either. xHTML 1.0 states, Include a space before the trailing / and > of empty elements, e.g. <br />, <hr /> and <img src="karen.jpg" alt="Karen" />. Also, use the minimized tag syntax for empty elements, e.g. <br />, as the alternative syntax <br></br> allowed by XML gives uncertain results in many existing user agents. [Elementary Emphasis.]

[Note: This article by Jukka Korpela thoroughly exposes the mysteries (and, conundrums) of the element: Empty elements in SGML, HTML, XML, and XHTML.]

Element tag:
<base>
Closure:
HTML 4.01 - <base>, i.e., No change
HTML 5 - Either closure type
xHTML 1.0 - <base(Single space) />

Use Examples

Example [Sôle]:
Code [HTML]:

<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Sweet — Sultry — Swanky | Théâtre Burlesque</title>
<base href="http://www.somnambulistes.org/">
<link rel="stylesheet"; type="text/css" href="styles/lafeeverte.css" media="screen,projection">
<script type="text/javascript" src="js/peepshow.js"></script>
</head>

Code [xHTML]:

<head>
<meta http-equiv="content-type" content="text/html; charset=utf-" />
<title>Sweet — Sultry — Swanky | Théâtre Burlesque</title>
<base href="http://www.somnambulistes.org/" />
<link rel="stylesheet" type="text/css" href="styles/lafeeverte.css" media="screen,projection" />
<script type="text/javascript" src="js/peepshow.js"></script>
</head>


Content Model/Assigned Attributes

Element-Type:
Empty
Attributes: