base
Definition
To resolve relative URLs, Web browsers will use the base URL from where the Web page was downloaded. In some circumstances, it is necessary to instruct the Web browser to use a different base URL, in which case the base
element is used.
Example
In the following example, regardless of where the Web page was downloaded from, the CSS file will be downloaded from http://xstandard.com/screen.css and the image will be downloaded from http://xstandard.com/images/logo.gif.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<base href="http://xstandard.com" />
- <style type="text/css">@import url('screen.css');</style>
</head>
<body>
<h1><img src="images/logo.gif" alt="XStandard" /></h1>
</body>
</html>
Best practice
If the base
element is to be used, it should be defined before any relative URL is used.
Attributes
Basic
href
- (URI) Specifies an absolute URL that acts as the base URL for resolving relative URLs. This attribute is required.
Contains