Codectionary / Developer documentation / HTML

<base>

The <base> element specifies a base URL and/or target for all relative URLs in a document. It must appear inside <head>, and a document should have no more than one <base> element. Once set, every relative link, image src, and form action on the page resolves against it unless individually overridden.

Syntax

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

Examples

Base URL

Setting a base so relative links resolve consistently.

<head>
  <base href="https://codectionary.com/docs/">
</head>
<body>
  <a href="html">HTML Docs</a>
  <!-- resolves to https://codectionary.com/docs/html -->
</body>

Base Target

Making every link on the page open in a new tab by default.

<head>
  <base target="_blank">
</head>
<body>
  <a href="https://example.com">Opens in new tab</a>
</body>

Combined href and target

Setting both a base URL and default target together.

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

Attributes

  • href (URL): The base URL for all relative URLs in the document
  • target (_blank | _self | _parent | _top): The default target for all links and forms

Best practices

  • Use at most one <base> element per document, placed early inside <head>
  • Be careful with base href — it affects every relative URL on the page, including images and scripts, not just links
  • Prefer explicit absolute or relative paths over relying on base href for most projects, since it can cause confusing bugs when forgotten
  • Remember individual links can still override a base target with their own target attribute

At a glance

Purpose
Structure and meaning for web content
File extension
.html · .htm
Runs in
Web browsers
Usually used with
CSS and JavaScript

Specifications & further reading

Related HTML documentation