HTML / HTML Tags

HTML <Base> Tag

Dec 12, 2022
2 min read
HTML base Tag

Definition

The <base> Tag specifies the base URL for all relative URLs used in your web page.

Example

<head>
  <base href="https://www.thewebmaster.com/" target="_blank">
</head>

<body>
<a href="/seo/">View SEO articles</a>.
</body>

Usage

  • There can only be one <base> element in a document. If multiple are used, only the first href and target attributes are used.

  • The <base> element must be contained in the <head>. It must come before any other elements with attribute values of URLs, such as the <link> element’s href attribute.

  • The <base> element does not have a closing tag.

  • In-page anchors use the <base>. If you wish to link to something on the same page, you will also need to specify the directory in the href attribute.

    For example:

    <head>
      <base href="https://www.thewebmaster.com/" target="_blank">
    </head>
    
    <body>
    <p><a href="#best-practices">View best practices</a> links to https://www.thewebmaster.com/#best-practices.</p>
    <p><a href="develop/reference/html/tags/base/#best-practices">View best practices</a> links to https://www.thewebmaster.com/html/tags/base/#best-practices.</p>
    </body>

  • Open Graph tags do not use <base>.

Attributes

The Base element supports the Global Attributes, as well as the following:

  • href

    The href attribute specifies the base URL of the page used for all relative links.

    <a href="https://www.thewebmaster.com" >Visit The Webmaster</a>
  • target

    The target attribute when used with the <base> element specifies the default way to open <a>, <area>, or <form> elements. You can override it by specifying a <target> attribute on any of those elements.

    Values can include:

    • _blank
    • _parent
    • _self
    • _top

Specification

Browser Support

Desktop

ChromeEdgeFirefoxIEOperaSafari
YesYesYesYesYesYes

Mobile

Android WebviewChrome AndroidFirefox AndroidOpera AndroidiOS SafariSamsung Internet
YesYesYesYesYesYes