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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
|
---
title: class
slug: Web/SVG/Attribute/href
translation_of: Web/SVG/Attribute/href
---
<div>{{SVGRef}}</div>
<p>The <strong><code>href</code></strong> attribute defines a link to a resource as a reference <a href="/en-US/docs/Web/SVG/Content_type#URL">URL</a>. The exact meaning of that link depends on the context of each element using it.</p>
<div class="note">
<p><strong>Note:</strong> Specifications before SVG 2 defined an {{SVGAttr("xlink:href")}} attribute, which is now rendered obsolete by the <code>href</code> attribute.</p>
</div>
<p>Fifteen elements are using this attribute: {{SVGElement("a")}}, {{SVGElement("animate")}}, {{SVGElement("animateMotion")}}, {{SVGElement("animateTransform")}}, {{SVGElement("discard")}}, {{SVGElement("feImage")}}, {{SVGElement("image")}}, {{SVGElement("linearGradient")}}, {{SVGElement("mpath")}}, {{SVGElement("pattern")}}, {{SVGElement("radialGradient")}}, {{SVGElement("script")}}, {{SVGElement("set")}}, {{SVGElement("textPath")}}, and {{SVGElement("use")}}</p>
<div id="topExample">
<div class="hidden">
<pre class="brush: css">html, body, svg {
height: 100%;
}</pre>
</div>
<pre class="brush: html; hightlight[2]"><svg viewBox="0 0 160 40" xmlns="http://www.w3.org/2000/svg">
<a href="https://developer.mozilla.org/"><text x="10" y="25">MDN Web Docs</text></a>
</svg></pre>
<p>{{EmbedLiveSample("topExample", "320", "100")}}</p>
</div>
<h2 id="In_SVG">In SVG</h2>
<h3 id="a">a</h3>
<p>For {{SVGElement("a")}}, <code>href</code> defines the location of the referenced object, expressed as a URL reference.</p>
<table class="properties">
<tbody>
<tr>
<th scope="row">Value</th>
<td><code><a href="/en-US/docs/Web/SVG/Content_type#URL"><url></a></code></td>
</tr>
<tr>
<th scope="row">Default value</th>
<td><em>None</em></td>
</tr>
<tr>
<th scope="row">Animatable</th>
<td>Yes</td>
</tr>
</tbody>
</table>
<h3 id="animate_animateMotion_animateTransform_set">animate, animateMotion, animateTransform, set</h3>
<p>For the {{SVGElement("animate")}}, {{SVGElement("animateMotion")}}, {{SVGElement("animateTransform")}}, and {{SVGElement("set")}}, <code>href</code> defines a URL referring to the element which is the target of this animation element and which therefore will be modified over time.</p>
<p>The URL must point to exactly one target element which is capable of being the target of the given animation element. If the URL points to multiple target elements, if the given target element is not capable of being a target of the given animation element, or if the given target element is not part of the current document, then the animation element will not affect any target element. However, the animation element will still operate normally with regard to its timing properties. Specifically, TimeEvents are dispatched and the animation element can be used as syncbase in an identical fashion to when the URL refers to a valid target element.</p>
<p>If the <code>href</code> attribute or the deprecated {{SVGAttr("xlink:href")}} attribute is not provided, then the target element will be the immediate parent element of the current animation element. If both <code>xlink:href</code> and <code>href</code> are specified, the value of the latter attribute is used.</p>
<p>Refer to the descriptions of the individual animation elements for any restrictions on what types of elements can be targets of particular types of animations.</p>
<p>Except for any SVG-specific rules explicitly mentioned in this specification, the normative definition for this attribute is the {{Glossary("SMIL")}} Animation specification. In particular, see <a href="https://www.w3.org/TR/2001/REC-smil-animation-20010904/#SpecifyingAnimationTarget">SMIL Animation: Specifying the animation target</a>.</p>
<table class="properties">
<tbody>
<tr>
<th scope="row">Value</th>
<td><code><a href="/en-US/docs/Web/SVG/Content_type#URL"><url></a></code></td>
</tr>
<tr>
<th scope="row">Default value</th>
<td><em>None</em></td>
</tr>
<tr>
<th scope="row">Animatable</th>
<td>No</td>
</tr>
</tbody>
</table>
<h3 id="discard">discard</h3>
<p>For {{SVGElement("discard")}}, <code>href</code> defines a URL referring the target element to discard. See the <a href="#href_on_animation_elements">definition of <code>href</code> on animation elements</a> for details on identifying a target element.</p>
<div class="blockIndicator note">
<p><strong>Note:</strong> Unlike other animation elements, the <code><discard></code> element does not support the deprecated {{SVGAttr("xlink:href")}} attribute.</p>
</div>
<p>Note that if the target element is not part of the current SVG document fragment, then whether the target element will be removed or not is defined by the host language.</p>
<p>If the <code>href</code> attribute is not provided, then the target element will be the immediate parent element of the <code><discard></code> element.</p>
<table class="properties">
<tbody>
<tr>
<th scope="row">Value</th>
<td><code><a href="/en-US/docs/Web/SVG/Content_type#URL"><url></a></code></td>
</tr>
<tr>
<th scope="row">Default value</th>
<td><em>None</em></td>
</tr>
<tr>
<th scope="row">Animatable</th>
<td>No</td>
</tr>
</tbody>
</table>
<h3 id="feImage">feImage</h3>
<p>For {{SVGElement("feImage")}}, <code>href</code> defines a URL referring to an image resource or to an element. If both, the {{SVGAttr("xlink:href")}} and the <code>href</code> attribute are specified, the latter overrides the former.</p>
<table class="properties">
<tbody>
<tr>
<th scope="row">Value</th>
<td><code><a href="/en-US/docs/Web/SVG/Content_type#URL"><url></a></code></td>
</tr>
<tr>
<th scope="row">Default value</th>
<td><em>None</em></td>
</tr>
<tr>
<th scope="row">Animatable</th>
<td>Yes</td>
</tr>
</tbody>
</table>
<h3 id="image">image</h3>
<p>For {{SVGElement("image")}}, <code>href</code> defines a URL referring to the image to render.</p>
<table class="properties">
<tbody>
<tr>
<th scope="row">Value</th>
<td><code><a href="/en-US/docs/Web/SVG/Content_type#URL"><url></a></code></td>
</tr>
<tr>
<th scope="row">Default value</th>
<td><em>None</em></td>
</tr>
<tr>
<th scope="row">Animatable</th>
<td>Yes</td>
</tr>
</tbody>
</table>
<h4 id="Example">Example</h4>
<div id="imageExample">
<div class="hidden">
<pre class="brush: css">html, body, svg {
height: 100%;
}</pre>
</div>
<pre class="brush: html"><svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
<image href="/files/2917/fxlogo.png" x="0" y="0" height="100" width="100"/>
</svg></pre>
<p>{{EmbedLiveSample("imageExample", 200, 250)}}</p>
</div>
<h3 id="linearGradient">linearGradient</h3>
<p>For {{SVGElement("linearGradient")}}, <code>href</code> defines URL referring to a template gradient element; to be valid, the reference must be to a different <code><linearGradient></code> or {{SVGElement("radialGradient")}} element.</p>
<table class="properties">
<tbody>
<tr>
<th scope="row">Value</th>
<td><code><a href="/en-US/docs/Web/SVG/Content_type#URL"><url></a></code></td>
</tr>
<tr>
<th scope="row">Default value</th>
<td><em>None</em></td>
</tr>
<tr>
<th scope="row">Animatable</th>
<td>Yes</td>
</tr>
</tbody>
</table>
<h3 id="mpath">mpath</h3>
<p>For {{SVGElement("mpath")}}, <code>href</code> defines a URL referring to the {{SVGElement("path")}} element or <a href="/en-US/docs/Web/CSS/CSS_Shapes/Basic_Shapes">basic shape</a> which defines the motion path.</p>
<table class="properties">
<tbody>
<tr>
<th scope="row">Value</th>
<td><code><a href="/en-US/docs/Web/SVG/Content_type#URL"><url></a></code></td>
</tr>
<tr>
<th scope="row">Default value</th>
<td><em>None</em></td>
</tr>
<tr>
<th scope="row">Animatable</th>
<td>No</td>
</tr>
</tbody>
</table>
<h3 id="pattern">pattern</h3>
<p>For {{SVGElement("pattern")}}, <code>href</code> defines a URL referring to a different <code><pattern></code> element within the current SVG document. Any attributes which are defined on the referenced element which are not defined on this element are inherited by this element. If this element has no children, and the referenced element does (possibly due to its own <code>href</code> attribute), then this element inherits the children from the referenced element. Inheritance can be indirect to an arbitrary level; thus, if the referenced element inherits attributes or children due to its own <code>href</code> attribute, then the current element can inherit those attributes or children. On the {{SVGElement("pattern")}} element, the <code>href</code> attribute is animatable.</p>
<table class="properties">
<tbody>
<tr>
<th scope="row">Value</th>
<td><code><a href="/en-US/docs/Web/SVG/Content_type#URL"><url></a></code></td>
</tr>
<tr>
<th scope="row">Default value</th>
<td><em>None</em></td>
</tr>
<tr>
<th scope="row">Animatable</th>
<td>Yes</td>
</tr>
</tbody>
</table>
<h3 id="radialGradient">radialGradient</h3>
<p>For {{SVGElement("radialGradient")}}, <code>href</code> defines URL referring to a template gradient element; to be valid, the reference must be to a different {{SVGElement("linearGradient")}} or <code><radialGradient></code> element.</p>
<table class="properties">
<tbody>
<tr>
<th scope="row">Value</th>
<td><code><a href="/en-US/docs/Web/SVG/Content_type#URL"><url></a></code></td>
</tr>
<tr>
<th scope="row">Default value</th>
<td><em>None</em></td>
</tr>
<tr>
<th scope="row">Animatable</th>
<td>Yes</td>
</tr>
</tbody>
</table>
<h3 id="script">script</h3>
<p>For {{SVGElement("script")}}, <code>href</code> defines a URL referring to an external resource containing the script code.</p>
<table class="properties">
<tbody>
<tr>
<th scope="row">Value</th>
<td><code><a href="/en-US/docs/Web/SVG/Content_type#URL"><url></a></code></td>
</tr>
<tr>
<th scope="row">Default value</th>
<td><em>None</em></td>
</tr>
<tr>
<th scope="row">Animatable</th>
<td>No</td>
</tr>
</tbody>
</table>
<h3 id="textPath">textPath</h3>
<p>For {{SVGElement("textPath")}}, <code>href</code> defines a URL referring to the {{SVGElement("path")}} element or <a href="/en-US/docs/Web/CSS/CSS_Shapes/Basic_Shapes">basic shape</a> onto which the text will be rendered if no {{SVGAttr("path")}} attribute is provided. On the {{SVGElement("textPath")}} element, the <code>href</code> attribute is animatable.</p>
<table class="properties">
<tbody>
<tr>
<th scope="row">Value</th>
<td><code><a href="/en-US/docs/Web/SVG/Content_type#URL"><url></a></code></td>
</tr>
<tr>
<th scope="row">Default value</th>
<td><em>None</em></td>
</tr>
<tr>
<th scope="row">Animatable</th>
<td>Yes</td>
</tr>
</tbody>
</table>
<h3 id="use">use</h3>
<p>For {{SVGElement("use")}}, <code>href</code> defines a URL referring to an element or fragment within an SVG document to be cloned.</p>
<p>The <code><use></code> element can reference an entire SVG document by specifying an <code>href</code> value without a fragment. Such references are taken to be referring to the root element of the referenced document.</p>
<table class="properties">
<tbody>
<tr>
<th scope="row">Value</th>
<td><code><a href="/en-US/docs/Web/SVG/Content_type#URL"><url></a></code></td>
</tr>
<tr>
<th scope="row">Default value</th>
<td><em>None</em></td>
</tr>
<tr>
<th scope="row">Animatable</th>
<td>Yes</td>
</tr>
</tbody>
</table>
<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("SVG2", "linking.html#AElementHrefAttribute", "href for <a>")}}</td>
<td>{{Spec2("SVG2")}}</td>
<td>Defines <code>href</code> for the {{SVGElement("a")}} element.</td>
</tr>
<tr>
<td>{{SpecName("SVG Animations 2", "#HrefAttribute", "href for <animate>, <animateMotion>, <animateTransform>, and <set>")}}</td>
<td>{{Spec2("SVG Animations 2")}}</td>
<td>Defines <code>href</code> for animation elements.</td>
</tr>
<tr>
<td>{{SpecName("SVG Animations 2", "#DiscardElementHrefAttribute", "href for <discard>")}}</td>
<td>{{Spec2("SVG Animations 2")}}</td>
<td>Defines <code>href</code> for the {{SVGElement("discard")}} element.</td>
</tr>
<tr>
<td>{{SpecName("Filters 1.0", "#element-attrdef-feimage-href", "href for <feImage>")}}</td>
<td>{{Spec2("SVG2")}}</td>
<td>Defines <code>href</code> for the {{SVGElement("feImage")}} element.</td>
</tr>
<tr>
<td>{{SpecName("SVG2", "embedded.html#ImageElementHrefAttribute", "href for <image>")}}</td>
<td>{{Spec2("SVG2")}}</td>
<td>Defines <code>href</code> for the {{SVGElement("image")}} element.</td>
</tr>
<tr>
<td>{{SpecName("SVG2", "pservers.html#LinearGradientElementHrefAttribute", "href for <linearGradient>")}}</td>
<td>{{Spec2("SVG2")}}</td>
<td>Defines <code>href</code> for the {{SVGElement("linearGradient")}} element.</td>
</tr>
<tr>
<td>{{SpecName("SVG Animations 2", "#MPathElementHrefAttribute", "href for <mpath>")}}</td>
<td>{{Spec2("SVG Animations 2")}}</td>
<td>Defines <code>href</code> for the {{SVGElement("mpath")}} element.</td>
</tr>
<tr>
<td>{{SpecName("SVG2", "pservers.html#PatternElementHrefAttribute", "href for <pattern>")}}</td>
<td>{{Spec2("SVG2")}}</td>
<td>Defines <code>href</code> for the {{SVGElement("pattern")}} element.</td>
</tr>
<tr>
<td>{{SpecName("SVG2", "pservers.html#RadialGradientElementHrefAttribute", "href for <radialGradient>")}}</td>
<td>{{Spec2("SVG2")}}</td>
<td>Defines <code>href</code> for the {{SVGElement("radialGradient")}} element.</td>
</tr>
<tr>
<td>{{SpecName("SVG2", "interact.html#ScriptElementHrefAttribute", "href for <script>")}}</td>
<td>{{Spec2("SVG2")}}</td>
<td>Defines <code>href</code> for the {{SVGElement("script")}} element.</td>
</tr>
<tr>
<td>{{SpecName("SVG2", "text.html#TextPathElementHrefAttribute", "href for <textPath>")}}</td>
<td>{{Spec2("SVG2")}}</td>
<td>Defines <code>href</code> for the {{SVGElement("textPath")}} element.</td>
</tr>
<tr>
<td>{{SpecName("SVG2", "struct.html#UseElementHrefAttribute", "href for <use>")}}</td>
<td>{{Spec2("SVG2")}}</td>
<td>Defines <code>href</code> for the {{SVGElement("use")}} element.</td>
</tr>
</tbody>
</table>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<p>{{Compat("svg.attributes.href")}}</p>
<h2 id="See_also">See also</h2>
<ul>
<li>{{SVGAttr("xlink:href")}}</li>
</ul>
|