<base>

Defines the base url for all relative links in an HTML page.
2 min read
Believemy logo

The <base> tag defines a base URL and/or a default target for all links in an HTML page.

It is declared within the <head> tag so that it can become a common reference for all elements that redirect the user, such as the <a>, <img>, or <link> tags, for example.

Warning

Caution: when used, it should be defined only once in the HTML document. 👀

 

Structure and syntax of the <base> tag

Basic structure and syntax

The <base> tag is a self-closing tag, meaning it does not contain any content and does not have a closing tag: it closes itself.

It always follows this structure:

HTML
<base href="[base URL]">

At a minimum, the href attribute is used to define the base URL for all relative links on the current page.

 

Usage example

Let's take a small example!

HTML
<!DOCTYPE html>
<html lang="en">
<head>
  <base href="https://www.believemy.com" target="_blank">
</head>
<body>
  <a href="/formations">View trainings</a>
</body>
</html>

In this example:

  • the original URL is /formations;
  • the final URL will be https://believemy.com/formations.

 

Attributes

The <base> tag can be used to define both the base URL and the default target for links.

AttributeDescriptionExample
hrefDefines the base URL from which all relative URLs will be resolved.<base href="https://www.example.com/">
targetDefines a default target for all links and forms in the document.<base target="_blank">
Good to know

Here are the possible values for the target attribute:

ValueDescription
_selfLoads the link in the same window or tab (default behavior).
_blankOpens the link in a new tab or window.
_parentLoads the link in the parent window of the document if present.
_topLoads the link in the outermost window (at the root document level).

 

Browser compatibility

The <base> instruction is compatible with all browsers.

ElementGoogle ChromeSafariMozilla FirefoxEdge
<base>YesYesYesYes

Related terms

Discover our hTML and CSS glossary

Browse the terms and definitions most commonly used in HTML and CSS development.

Share this article

Want to help us? Share this article on your networks or even better: on your site, in an article or in your newsletter.