HTML <base> tag
When writing in HTML (hypertext markup language), the <base> tag designates the base URL (uniform resource locator) for every relative URL inside of a document. This tag may only be used once, and it must be contained in the <head> of the page. The following sections contain information about this tag, including an example of it in use, and related attributes and browser compatibility.
Example code
<head> <base href="/"> </head> <body> <img src="chguy.gif" width="57" height="120" alt="Hope Guy"> </body>
The above code, rendered in a web browser:
Notice we can load the Computer Hope Guy image using only the relative path because we specified the absolute path in the <base> tag in the <head>. In other words, the current URL is: https://www.computerhope.com/jargon/h/html-base-tag.htm. Normally, the browser would try to load "chguy.gif" from the https://www.computerhope.com/jargon/h/ directory because it's the same directory as the "html-base-tag.htm" file. However, because the base tag devices the base as https://www.computerhope.com/ it loads "chguy.gif" as https://www.computerhope.com/chguy.gif.
You can add the <base target="_blank"> to the header section of your page to have all links open in a new window or tab.
Attributes
All HTML tags support standard attributes that define the settings of an HTML element. In addition to the standard settings, the <base> tag has the following unique attributes.
Attribute | Description |
---|---|
href | Designates the URL of the web page where the link points. |
target | Designates the target for all of the hyperlinks in a page. |
Compatibility
Edge | Internet Explorer | Firefox | Safari | Opera | Chrome |
---|---|---|---|---|---|
All versions | All versions | All versions | All version | All versions | All versions |