HTML: the base element

The <base> element sets the base URL used to resolve relative URLs and can set the default target for links on a page.

What you will learn

Set a base URL

<head>
  <base href="https://example.com/docs/">
</head>
<body>
  <a href="start.html">Start guide</a>
</body>

With this base URL, start.html resolves to https://example.com/docs/start.html. The base URL is not the same as the page's canonical URL; use the canonical link separately when search engines need it.

Set the default target

<base href="https://example.com/" target="_self">

The target value applies to links and forms that do not specify their own target. Prefer _self unless there is a clear reason to open content elsewhere, and make new-window behavior understandable to users.

Common mistakes