HTML <base> Tag

Definition and Usage

<base> The tag defines the base URL and/or target for all relative URLs in the document.

In most cases, browsers will extract the corresponding elements from the current document's URL to fill in the blanks in the relative URL.

Using <base> The tag can change this. Browsers will then no longer use the current document's URL to resolve all relative URLs, but use the specified base URL. This includes URLs in <a>, <img>, <link>, <form> tags.

<base> The tag must have href or target attribute, or both.

Only one in a document can have <base> element, and it must be located The <head> element Internally, it is usually one of the first child elements of the head element, so that relative URLs in subsequent metadata elements can use the base URL set by it.

See also:

HTML DOM Reference Manual:Base Object

Example

Specify the default URL and default target for all links on the page:

<head>
  <base href="https://www.codew3c.com/" target="_blank">
</head>
<body>
<img src="i/photo/tree.png" width="150" height="161" alt="Tree">
<a href="tags/tag_base.asp">HTML base tag</a>
</body>

Try It Yourself

Attribute

Attribute Value Description
href URL Specifies the base URL for all relative URLs in the page.
target
  • _blank
  • _parent
  • _self
  • _top
Specifies the default target for all hyperlinks and forms in the page.

Global Attributes

<base> The tag also supports Global Attributes in HTML.

Event Attributes

<base> The tag does not support any event attributes.

Default CSS Settings

None.

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support Support Support Support Support