Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 931781 of <base>

  • Revision slug: Web/HTML/Element/base
  • Revision title: <base>
  • Revision id: 931781
  • Created:
  • Creator: teoli
  • Is current revision? No
  • Comment More cleaning

Revision Content

{{HTMLRef}}

The HTML <base> Element specifies the base URL to use for all relative URLs contained within a document. There can be only one <base> element in a document. 

The base URL of a document can be queried from a script using {{domxref('document.baseURI')}}.

Usage Note: If multiple <base> elements are specified, only the first href and first target value are used; all others are ignored.
  • Content categories Metadata content.
  • Permitted content None, it is an {{Glossary("empty element")}}.
  • Tag omission There must be no closing tag.
  • Permitted parent elements Any {{HTMLElement("head")}} that doesn't contain any other {{HTMLElement("base")}} element
  • DOM interface {{domxref("HTMLBaseElement")}}

Attributes

This element includes the global attributes.

{{htmlattrdef("href")}}
The base URL to be used throughout the document for relative URL addresses. If this attribute is specified, this element must come before any other elements with attributes whose values are URLs. Absolute and relative URIs are allowed.
{{htmlattrdef("target")}}
A name or keyword indicating the default location to display the result when hyperlinks or forms cause navigation, for elements that do not have an explicit target reference. It is a name of, or keyword for, a browsing context (for example, tab, window, or inline frame). The following keywords have special meanings:
  • _self: Load the result into the same browsing context)as the current one. This value is the default if the attribute is not specified.
  • _blank: Load the result into a new unnamed browsing context.
  • _parent: Load the result into the parent browsing context of the current one. If there is no parent, this option behaves the same way as _self.
  • _top: Load the result into the top-level browsing context (that is, the browsing context that is an ancestor of the current one, and has no parent). If there is no parent, this option behaves the same way as _self.

Examples

<base href="https://www.example.com/page.html">
<base target="_blank" href="https://www.example.com/page.html">  

Specifications

Specification Status Comment
{{SpecName('HTML WHATWG', 'semantics.html#the-base-element', '<base>')}} {{Spec2('HTML WHATWG')}} No change since last snapshot.
{{SpecName('HTML5 W3C', 'document-metadata#the-base-element', '<base>')}} {{Spec2('HTML5 W3C')}} Precised the behavior of target
{{SpecName('HTML4.01', 'struct/links.html#h-12.4', '<base>')}} {{Spec2('HTML4.01')}} Added the target attribute

Browser compatibility

{{CompatibilityTable}}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support {{CompatVersionUnknown}} {{CompatGeckoDesktop("1.0")}} [1] {{CompatVersionUnknown}} [2] {{CompatVersionUnknown}} {{CompatVersionUnknown}}
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{CompatVersionUnknown}} {{CompatGeckoMobile("1.0")}} [1] {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}}

[1] Support of relative URIs for href was added in Gecko 2.0 (Firefox 4.0)

[2] Before Internet Explorer 7, <base> could be positioned anywhere in the document and the nearest value of <base> was used. Support for relative URLs has been removed in Internet Explorer 8

Revision Source

<p id="Summary">{{HTMLRef}}</p>

<p>The <strong>HTML <code>&lt;base&gt;</code> Element</strong> specifies the base URL to use for all relative URLs contained within a document. There can be only one &lt;base&gt; element in a document.&nbsp;</p>

<p>The base URL of a document can be queried from a script using {{domxref('document.baseURI')}}.</p>

<div class="note"><strong>Usage Note:</strong> If multiple <code>&lt;base&gt;</code> elements are specified, only the first <strong>href</strong> and first <strong>target</strong> value are used; all others are ignored.</div>

<ul class="htmlelt">
 <li><dfn><a href="/en-US/docs/HTML/Content_categories" title="HTML/Content_categories">Content categories</a></dfn> Metadata content.</li>
 <li><dfn>Permitted content</dfn> None, it is an {{Glossary("empty element")}}.</li>
 <li><dfn>Tag omission</dfn> There must be no closing tag.</li>
 <li><dfn>Permitted parent elements</dfn> Any {{HTMLElement("head")}} that doesn't contain any other {{HTMLElement("base")}} element</li>
 <li><dfn>DOM interface</dfn> {{domxref("HTMLBaseElement")}}</li>
</ul>

<h2 id="Attributes">Attributes</h2>

<p><span style="line-height:21px">This element includes the&nbsp;</span><a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes" style="line-height: 21px;" title="HTML/Global attributes">global attributes</a><span style="line-height:21px">.</span></p>

<dl>
 <dt>{{htmlattrdef("href")}}</dt>
 <dd>The base URL to be used throughout the document for relative URL addresses. If this attribute is specified, this element must come before any other elements with attributes whose values are URLs. Absolute and relative URIs are allowed.</dd>
 <dt>{{htmlattrdef("target")}}</dt>
 <dd>A name or keyword indicating the default location to display the result when hyperlinks or forms cause navigation, for elements that do not have an explicit target reference. It is a name of, or keyword for, a <em>browsing context</em> (for example, tab, window, or inline frame). The following keywords have special meanings:
 <ul>
  <li><code>_self</code>: Load the result into the same browsing context)as the current one. This value is the default if the attribute is not specified.</li>
  <li><code>_blank</code>: Load the result into a new unnamed browsing context.</li>
  <li><code>_parent</code>: Load the result into the parent browsing context of the current one. If there is no parent, this option behaves the same way as <code>_self</code>.</li>
  <li><code>_top</code>: Load the result into the top-level browsing context (that is, the browsing context that is an ancestor of the current one, and has no parent). If there is no parent, this option behaves the same way as <code>_self</code>.</li>
 </ul>
 </dd>
</dl>

<h2 id="Examples">Examples</h2>

<pre class="brush: html">
&lt;base href="https://www.example.com/page.html"&gt;
&lt;base target="_blank" href="https://www.example.com/page.html"&gt;  
</pre>

<h2 id="Specifications" name="Specifications">Specifications</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('HTML WHATWG', 'semantics.html#the-base-element', '&lt;base&gt;')}}</td>
   <td>{{Spec2('HTML WHATWG')}}</td>
   <td>No change since last snapshot.</td>
  </tr>
  <tr>
   <td>{{SpecName('HTML5 W3C', 'document-metadata#the-base-element', '&lt;base&gt;')}}</td>
   <td>{{Spec2('HTML5 W3C')}}</td>
   <td>Precised the behavior of <code>target</code></td>
  </tr>
  <tr>
   <td>{{SpecName('HTML4.01', 'struct/links.html#h-12.4', '&lt;base&gt;')}}</td>
   <td>{{Spec2('HTML4.01')}}</td>
   <td>Added the <code>target</code> attribute</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<p>{{CompatibilityTable}}</p>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatGeckoDesktop("1.0")}} [1]</td>
   <td>{{CompatVersionUnknown}} [2]</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Mobile</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatGeckoMobile("1.0")}} [1]</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<p>[1] Support of relative URIs for <code>href</code> was added in Gecko 2.0 (Firefox 4.0)</p>

<p>[2] Before Internet Explorer 7, <code>&lt;base&gt;</code> could be positioned anywhere in the document and the nearest value of <code>&lt;base&gt;</code> was used. Support for relative URLs has been removed in Internet Explorer 8</p>
Revert to this revision