Why Every Link Opens in a New Tab: Check the HTML base target Element

Find out why an HTML base target opens all links in a new tab, how to inspect shared templates, and how to override link and form targets.

Published
Reading time
6 min read
Why Every Link Opens in a New Tab: Check the HTML base target Element
On this page

If links across a site unexpectedly open in new tabs, inspect the shared document head for <base target="_blank">. A base element can set the default browsing context for both links and forms, even when those elements have no target attribute of their own.

This guide shows how to identify that default, override it for individual elements, and fix it in a shared template. The examples are illustrative and were not executed; the WHATWG HTML Standard and MDN documentation could not be consulted in this environment, so check them for current browser-specific details.

Key Takeaways

  • <base target="_blank"> supplies a default target for links and forms that do not specify their own nonempty target.
  • An explicit target such as _self overrides that default for an individual link or form.
  • The default comes from the document’s base element, not from ordinary DOM ancestor inheritance.
  • If there is no applicable base target or individual target, navigation normally uses the current browsing context.

A shared template can include a base element in its head. Here, the links and form use _blank by default because they have no individual target:

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Base target example</title>
  <base target="_blank">
</head>
<body>
  <a href="/help">Help</a>

  <form action="/search" method="get">
    <label for="query">Search</label>
    <input id="query" name="q">
    <button type="submit">Search</button>
  </form>

  <a href="/account" target="_self">Account</a>
</body>
</html>

On a site serving those paths, the Help link and Search submission are intended to open a new browsing context, usually a tab. The Account link instead uses the current context because its explicit _self target overrides the base default. The paths are examples; the server must provide those endpoints for useful pages to appear. Browser settings or policies can affect how new contexts are displayed or whether they open.

A base element can also have an href attribute for resolving relative URLs. That is a separate function: target chooses a browsing context; it does not by itself change where a relative URL points.

Advertisement

Diagnostic checklist

  1. Inspect the rendered document head. In browser developer tools, search for <base and look for a target attribute. Check the live DOM as well as the server-rendered template: a script or template layer may have changed it.
  2. Check the relevant base target. A document can contain more than one base element, but the first one with a target attribute supplies the base target. The first base with an href is determined separately, so an href-only element can precede the element that supplies the target.
  3. Inspect the affected link or form. Look for its own target. A nonempty individual target takes precedence over the base target. For a submit button, also check formtarget, which can override the form’s target for that submission.
  4. Check the shared template and its variants. Find where the head is assembled, including layout components and injected markup. Compare affected and unaffected pages.
  5. If markup does not explain it, inspect behavior. JavaScript click or submit handlers, extensions, and browser settings can also affect navigation. Check whether a handler prevents the normal action or opens a window itself.

You can inspect the first base element carrying a target in the browser console:

const base = document.querySelector('base[target]');
console.log(base ? base.outerHTML : 'No base element with a target attribute');

For a selected link, the Elements panel shows its own attributes; the absence of target there does not mean _self if a base target applies. Do not mistake a parent element’s target attribute for an inherited link target: ordinary ancestors do not establish this default.

Change the default or override one element

If same-context navigation is the intended site-wide behavior, remove the target attribute from the shared base element. Keep its href, if present and needed for URL resolution:

<base href="/">

Alternatively, an explicit <base target="_self"> sets the default to the current context. Review existing links and forms first: elements with their own nonempty targets continue to use those targets.

When the global _blank default is intentional but one action should stay in the current context, override that element:

<a href="/account" target="_self">Account</a>

<form action="/search" method="get" target="_self">
  <label for="local-query">Search this site</label>
  <input id="local-query" name="q">
  <button type="submit">Search</button>
</form>

Use a nonempty explicit value when overriding the default; do not rely on an empty target to mean _self. Other special values have different effects: _parent navigates the parent browsing context, and _top navigates the top-level context. In a page without an enclosing frame, these can appear similar to _self. A named target can reuse a browsing context with that name, rather than necessarily opening a fresh tab each time.

Advertisement

Accessibility and security considerations

Unexpected tabs can disorient users, particularly when the browser’s Back button no longer returns to the originating page in the new tab. Prefer same-context navigation unless opening a separate context serves a clear purpose. When a link intentionally opens a new tab, make that behavior clear in its accessible link text or accompanying accessible description.

For an intentional new-tab link, an explicit rel="noopener" helps prevent the destination from using window.opener to manipulate the originating page. Modern browsers generally provide equivalent opener protection for _blank links, but explicit markup makes the intent clear and helps with environments where behavior may differ:

<a href="/report" target="_blank" rel="noopener">
  View report (opens in a new tab)
</a>

noopener is not a substitute for trusting or validating destinations. noreferrer also suppresses referrer information, which can affect analytics or integrations; use it when that privacy behavior is wanted, not as an unexplained replacement. A global _blank default makes it harder to identify which links need an explanation and review their security attributes.

Common Mistakes

  • Checking only the link’s HTML. A link without target="_blank" can still use the base target.
  • Removing the entire base element without checking href. That can change how relative URLs resolve throughout the document.
  • Assuming a link override changes forms. Each link or form needs its own override, or the shared default must change. A submitter’s formtarget also deserves inspection.
  • Assuming every unexpected tab comes from HTML. Script-driven navigation and browser configuration can produce similar symptoms.
  • Treating _self, _parent, and _top as interchangeable in embedded pages. They can navigate different contexts inside frames.

Best Practices

Keep the shared navigation default predictable and use explicit targets for exceptions. Before changing a layout, test representative links and form submissions, including pages embedded in frames and submit buttons with formtarget. Confirm both the rendered markup and the navigation behavior in the browsers your site supports.

Conclusion

When many unrelated links open new tabs, start with the document’s first <base target> rather than editing every link. Remove or change the shared default if it is unintended, and use explicit targets only where a different navigation context is needed.

What would your domain sell for?

A free TidyURLs account unlocks the Domain Estimator. It prices a name from 191,011 real domain sales.