HTML <base> Element
The <base> element specifies the base URL used to resolve relative URLs in an HTML document and can also specify a default target for hyperlinks and forms.
Syntax
<base href="https://www.example-web.site/">
The <base> element is a void element and does not use a closing tag. It must include an href attribute, a target attribute, or both.
Attributes
The <base> element supports the global HTML attributes and the following element-specific attributes:
| Attribute | Description |
|---|---|
href |
Specifies the base URL used to resolve relative URLs throughout the document. |
target |
Specifies the default target used for hyperlinks and form submissions that do not specify their own target. |
Example
The following example sets a base URL for relative URLs in the document:
<head>
<base href="https://www.example-web.site/tutorials/">
</head>
<body>
<a href="html-basics.html">HTML Basics</a>
</body>
Because the document has a base URL, the relative link html-basics.html is resolved as https://www.example-web.site/tutorials/html-basics.html.
Usage Notes
The <base> element belongs inside the document's <head>. A document must not contain more than one <base> element.
When href is used, the <base> element must appear before other elements containing URLs that are affected by the document's base URL.
When target is used, it establishes the default target for hyperlinks and forms that do not specify their own target value.
A base URL also affects fragment-only links. For example, href="#example" is resolved relative to the base URL rather than automatically referring only to the current document.
Because the <base> element can change how many URLs throughout a document are resolved, use it carefully when working with relative links, images, stylesheets, scripts, and other resources.
Browser Support
Baseline: Widely available indicates a feature has been supported by core browsers for at least 30 months. At this stage, the feature is considered stable and safe for most websites to use without needing to worry about compatibility issues or fallbacks, as it is supported by the vast majority of users' devices and browser versions.
For detailed browser compatibility information, see Can I Use: HTML <base> Element .
Some individual attributes and behaviors may have different levels of browser support.
Related Elements
<head> - Contains document metadata, including the <base> element.
<a> - Creates hyperlinks whose relative URLs can be affected by the document's base URL.
<link> - References external resources using URLs that can be resolved against the document's base URL.
<form> - Can use the default navigation target established by the <base> element.
