The <base> element

Defines either a base URI for resolving relative URIs after this, or a default value for target attributes, or both.

This is an empty element, so it shouldn't have a closing tag.

Validity

The <base> element is only allowed inside the <head> element. You're only allowed to have one of them in a particular document. It must have one of the attributes described below, either href or target. It is allowed to use both attributes on the same element.

The element must appear before anything that it affects. So if the href attribute is used, then it must appear before any elements that define a URI (so before any <link> elements for example). The URL in the manifest attribute of the <html> element is the only exception, and it won't be affected by <base> at all. If the target attribute is used then it must appear before any links that could have their own target attribute.

Base URL

The href attribute will set the base URI against which all relative URIs will be resolved. For example:

<base href="http://example.com/">

With the above code in your document, all the links (both clickable hyperlinks like <a> and other kinds of links like <link>) will be based at the example.com domain. Absolute links, which include the schema (http etc), will not be affected.

Default hyperlink target

The target attribute can be used to effectively provide a default value for the target attribute on any <a> links in the document. An individual link with its own target attribute will override the default given by <base> though. For example, this will make all links on a page (by default) open in a new window or tab:

<base target=_blank>

That's probably not a good idea though—user's get annoyed when their browser does unexpected things, and it's a bit much changing the way all links on a page work.

Full list of attributes

All the usual HTML global attributes are available

href
The base URI that all relative URIs should be resolved against.
target
The default browsing context, or a special keyword like _top. Defines where links should be opened if they don't override this with their own target attribute.

Further information

The Web Design Academy Contact us

By form

By Phone

+44 (0)113 234 4611

By email

enquiries@thewebdesign.academy

By snail mail

Suite 3 15 South Parade Leeds LS1 5PQ United Kingdom