<base> sets the document’s base URL for relative URLs, a default navigation target, or both. It belongs in head before elements with URL-valued attributes. Use at most one base element.
It must have href, target, or both. href alone is not required if target is present.
Inspect a complete document
HTML and CSS
HTML
<a id="lesson" href="layout.html">Layout lesson</a>
<p id="resolved"></p>
<script>
document.querySelector('#resolved').textContent =
document.querySelector('#lesson').href;
</script>
CSS
Edit HTML or CSS to update the preview as you type. Copy code snippet copies the selected tab. Preview spacing and font defaults are not included.
The displayed address is https://example.com/guides/layout.html. JavaScript only exposes the resolved address; the base URL itself is native HTML behavior. Inspect the anchor in developer tools or copy the document to compare its literal href with its resolved URL.
A practical use
A generated document that lives under a known root can resolve all its relative asset URLs from that root. Check every relative URL before adding a base: a stylesheet, image, form action, and fragment link can all change meaning.
Common mistakes
href="#section" also resolves against the base URL, so it can leave the current document. Multiple base elements are invalid authoring: browsers use the first href and first target. data: and javascript: base URLs are not allowed.
target="_blank" sets a default browsing target for links and forms that do not choose one themselves. Opening new tabs can surprise readers; use it only when the interface calls for that behavior. This site’s preview cannot open a new browsing context.
Sources and browser support
MDN: base describes the syntax and links to the specification and compatibility data. Check individual values in that table when supporting older browsers.