aboutsummaryrefslogtreecommitdiff
path: root/files/id/web/html/element/base/index.html
blob: 6b4a556381fd5124bdeb52c56f8928f8bc14933e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
---
title: <base>
slug: Web/HTML/Element/base
translation_of: Web/HTML/Element/base
---
<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 <code>&lt;base&gt;</code> element in a document. </p>

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

<table class="properties">
 <tbody>
  <tr>
   <th><a href="/en-US/docs/Web/HTML/Content_categories">Content categories</a></th>
   <td>Metadata content.</td>
  </tr>
  <tr>
   <th>Permitted content</th>
   <td>None, it is an {{Glossary("empty element")}}.</td>
  </tr>
  <tr>
   <th>Tag omission</th>
   <td>There must be no closing tag.</td>
  </tr>
  <tr>
   <th>Permitted parents</th>
   <td>Any {{HTMLElement("head")}} that doesn't contain any other {{HTMLElement("base")}} element</td>
  </tr>
  <tr>
   <th>Permitted ARIA roles</th>
   <td>None</td>
  </tr>
  <tr>
   <th>DOM interface</th>
   <td>{{domxref("HTMLBaseElement")}}</td>
  </tr>
 </tbody>
</table>

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

<p>This element's attributes include the <a href="/en-US/docs/HTML/Global_attributes">global attributes</a>.</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 URLs 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="Usage_notes">Usage notes</h2>

<p>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.</p>

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

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

<h2 id="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>Specified 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>Edge</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>{{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>Edge</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>{{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>