<base> Tag in HTML

Quick facts

CategoryMetadata content
Content modelEmpty — it’s a void element
Tag omissionVoid element — no end tag, ever
Permitted parentsA <head> element, with no other <base> on the page
DOM interfaceHTMLBaseElement

Syntax

<head> <base href="https://example.com/docs/" target="_blank"> </head>

Live example

Edit the code below and watch the preview update instantly.

index.html
Preview

Attributes

AttributeDescription
hrefThe base URL that relative URLs on the page are resolved against
targetThe default place links open, e.g. _blank for a new tab, unless a link sets its own

Common examples

A base URL for relative links

All relative links and images now resolve from the base address.

<head> <base href="https://example.com/docs/"> </head> <body> <a href="intro.html">Intro</a> <!-- → https://example.com/docs/intro.html --> </body>

A default link target

Every link without its own target opens in the named frame or tab.

<base target="_blank">

Fixing a #link after adding base

Hash links resolve against the base too, so include the page path or use JavaScript.

<!-- With <base href="/docs/">, href="#top" goes to /docs/#top --> <a href="/guide/page.html#top">Back to top</a>

<base> vs root-relative URLs

<base> changes how every relative URL on the page is resolved — links, images, stylesheets, scripts and form actions. That’s powerful, but easy to forget, and it causes confusing bugs later.

Root-relative URLs, starting with a slash (/images/logo.png), always point to the same place from any page, with no hidden setting. For most websites, root-relative URLs are simpler and safer; base is mostly useful for documents moved between locations, such as saved pages or email-like HTML.

<base>Root-relative URLs
AffectsEvery relative URLJust that URL
Risk of surprisesHighLow
Typical usePortable documentsMost websites

Common mistakes to avoid

  • Placing base after other links in the head. It must come before any element that uses a URL.
  • Forgetting the trailing slash. href="/docs" resolves relative links against /, not /docs/.
  • Using target="_blank" for every link. Opening everything in new tabs annoys visitors and can break the back button.
  • Forgetting that #anchor links change. They jump to the base URL instead of the current page.

Accessibility & SEO tips

  • Canonical and alternate links should use full absolute URLs anyway, so base doesn’t affect them.
  • A wrong base URL can make every image and stylesheet fail at once — test the whole page after adding one.
  • Search engines respect base when following relative links, so a mistake can create many broken URLs in their eyes.
  • If you inherit a page that uses base, check every link, image and form after any change to the site structure — it’s the first place broken URLs come from.

Browser support

Supported in every browser, including Chrome, Edge, Firefox, Safari and their mobile versions — it has been part of HTML since the very first versions.

Related tags

Frequently asked questions

Why did my #section links break after adding <base>?
Fragment links like href="#top" are resolved against the base URL too, so they point to the base address plus #top instead of the current page. Write the full path, or avoid <base> on pages that rely on in-page links.
Can a page have more than one <base> tag?
No. Only the first <base> with an href is used; the others are ignored. Keep a single one, early in the <head>.
Should I use <base target="_blank"> to open all links in new tabs?
It works, but forcing every link into a new tab often annoys visitors and affects accessibility. Prefer adding target="_blank" only to specific links that need it.
Where does the <base> tag go?
Inside the <head>, before any <link>, <script> or other element that uses a URL. Placing it first after <meta charset> is safest.
Does <base> affect JavaScript fetch() calls?
Yes. Relative URLs passed to fetch() and new URL() are resolved using the base URL of the document.
Should I use <base> on a WordPress site?
No. WordPress already produces correct full URLs, and adding base can break theme and plugin links.
Does <base> affect links in CSS files?
No. URLs inside an external stylesheet are resolved relative to the stylesheet's own location, not the page's base URL.
Can <base> use a relative URL?
Yes, for example <base href="/docs/">. It's resolved against the page's address, then used for all other relative URLs.
How do I remove the effect of <base> on one link?
Use a full absolute URL (https://…) or a root-relative URL starting with / on that link. Those aren't affected by the base href.