Description
HTML element <base>
is used to specify a base UTL, which is being used for all relative URLs on an HTML document.
Only one <base>
element is allowed on an HTML document.
The below table summarizes its usage.
Usage Details | |
Placement | It must be included within the <head> element. |
Contents | It is an empty element. |
Tags | Only an opening tag is required. |
Versions | HTML 2, 3.2, 4, 4.01, 5 |
Syntax
<base href="URL">
Examples
In the below example, the URLs of the logo and favicon are resolved using the base URL.
- Logo URL: https://randomcodez.com/assets/logo/logo.png
- Favicon URL: https://randomcodez.com/assets/favicon/favicon.ico
<!DOCTYPE html>
<html lang="en">
<head>
<!-- <base href="/"> -->
<!-- <base href="/" target="_blank"> -->
<base href="https://randomcodez.com/" target="_blank">
</head>
<body>
<h1>HTML Base Element</h1>
<p><a href="assets/logo/logo.png">Logo</a></p>
<p><a href="assets/favicon/favicon.ico">Favicon</a></p>
<p><a href="https://randomcodez.com">Website</a></p>
</body>
</html>
Attributes
The following table shows the list of supported and unsupported attributes for the <base>
tag.
Attribute Type | Details |
Tag-Specific Attributes | The tag <base> supports the below tag-specific attributes. |
Global Attributes | Like all other HTML tags, the tag <b> supports the HTML Global Attributes. |
Event Attributes | The tag <b> also supports the HTML Event Attributes. |
Browser Compatibility
The tag <b>
is supported in all modern browsers.
- Google Chrome 1+
- Internet Explorer or Edge 2+
- Firefox 1+
- Apple Safari 1+
- Opera 4+