HTML <base> Tag

The HTML <base> tag is used to create a 'base' element. This enables web authors to create a base URL for the purpose of resolving relative URLs.

For example, you can set the base URL once at the top of your page, then all relative links on the page will use that URL as if it was the current page.

Syntax

The <base> tag is written as <base href="" target=""> (no end tag). The <base> must have either an href attribute, a target attribute, or both.

Like this:

The <base> tag must be inserted between the document's <head> tags, and there must be no more than one <base> element per document.

Like this:

Example

The above link will actually resolve to http://www.html.am/html-editors/online-html-editor.cfm regardless of the URL of the current page. This is because the base URL (http://www.html.am/) will be prepended to the (relative) URL indicated in the link (html-editors/online-html-editor.cfm).

Modify the code and click Run to change the value of the <base> element.

Attributes

Attributes can be added to an HTML element to provide more information about how the element should appear or behave.

The <base> element accepts the following attributes.

AttributeDescription
hrefSpecifies the URI/URL to use.
targetTarget frame/window

Global Attributes

The following attributes are standard across all HTML elements. Therefore, you can use these attributes with the <base> tag , as well as with all other HTML tags.

For a full explanation of these attributes, see HTML 5 global attributes.

Event Handlers

Event handler content attributes enable you to invoke a script from within your HTML. The script is invoked when a certain "event" occurs. Each event handler content attribute deals with a different event.

Most event handler content attributes can be used on all HTML elements, but some event handlers have specific rules around when they can be used and which elements they are applicable to.

For more detail, see HTML event handler content attributes.