Deprecated since SVG 2
This feature has been removed from the Web standards. Though some browsers may still support it, it is in the process of being dropped. Do not use it in old or new projects. Pages or Web apps using it may break at any time.
« SVG Attribute reference home
The xlink:href
attribute defines a link to a resource as a reference <IRI>. The exact meaning of that link depends on the context of each element using it. See above for more specific usage.
Note: SVG 2 removed the need for the xlink
namespace, so instead of xlink:href
you should use href
.
An Internationalized Resource Identifier.
On the Internet, resources are identified using IRIs (Internationalized Resource Identifiers). For example, an SVG file called someDrawing.svg located at http://example.com might have the following IRI:
http://example.com/someDrawing.svg
An IRI can also address a particular element within an XML document by including an IRI fragment identifier as part of the IRI. An IRI which includes an IRI fragment identifier consists of an optional base IRI, followed by a "#" character, followed by the IRI fragment identifier. For example, the following IRI can be used to specify the element whose ID is "Lamppost" within file someDrawing.svg:
http://example.com/someDrawing.svg#Lamppost
IRIs are used in the xlink:href
attribute. Some attributes allow both IRIs and text strings as content. To disambiguate a text string from a relative IRI, the functional notation <FuncIRI> is used. This is simply an IRI delimited with a functional notation. Note: For historical reasons, the delimiters are "url(" and ")", for compatibility with the CSS specifications. The FuncIRI form is used in presentation attributes .
SVG makes extensive use of IRI references, both absolute and relative, to other objects. For example, to fill a rectangle with a linear gradient, you first define a <linearGradient>
element and give it an ID, as in:
<linearGradient xml:id="MyGradient">...</linearGradient>
You then reference the linear gradient as the value of the fill
attribute for the rectangle, as in the following example:
<rect fill="url(#MyGradient)"/>
SVG supports two types of IRI references:
<absoluteIRI>
or <relativeIRI>
and thus only contains a fragment identifier (i.e., #<elementID>
or #xpointer(id<elementID>)
)<absoluteIRI>
or <relativeIRI>
For the full specification of IRI references in SVG, see SVG 1.1 (2nd Edition): IRI references.
The following elements can use the xlink:href
attribute
xlink:href
attribute is not provided, then the target element will be the immediate parent element of the current animation element.<linearGradient>
or <radialGradient>
element within the current SVG document. Any <linearGradient>
or <linearGradient>
attributes which are defined on the referenced element which are not defined on this element are inherited by this element if this element is of the same type as the referenced element. If this element has no defined gradient stops, and the referenced element does (possibly due to its own xlink:href
attribute), then this element inherits the gradient stop from the referenced element. Inheritance can be indirect to an arbitrary level; thus, if the referenced element inherits attribute or gradient stops due to its own xlink:href
attribute, then the current element can inherit those attributes or gradient stops. On the gradient elements, the xlink:href
attribute is animatable.<a>
<a>
element, the xlink:href
attribute is animatable.<altGlyph>
<glyph>
element in an SVG document or to an <altGlyphDef>
element.<glyph>
element and that glyph is available, then that glyph is rendered instead of the character(s) that are inside of the <altGlyph>
element.<altGlyphDef>
element, then if an appropriate set of alternate glyphs is located from processing the <altGlyphDef>
element, then those alternate glyphs are rendered instead of the character(s) that are inside of the <altGlyph>
element.<color-profile>
<cursor>
<cursor>
element, the xlink:href
attribute is animatable.<feImage>
<feImage>
element, the xlink:href
attribute is animatable.<filter>
<filter>
element within the current SVG document. Any attributes which are defined on the referenced <filter>
element which are not defined on this element are inherited by this element. If this element has no defined filter nodes, and the referenced element has defined filter nodes (possibly due to its own xlink:href
attribute), then this element inherits the filter nodes defined from the referenced <filter>
element. Inheritance can be indirect to an arbitrary level; thus, if the referenced <filter>
element inherits attributes or its filter node specification due to its own xlink:href
attribute, then the current element can inherit those attributes or filter node specifications. On the <filter>
element, the xlink:href
attribute is animatable.<font-face-uri>
xlink:href
attribute specifies the location of the referenced font.<glyphRef>
<glyph>
element in an SVG document. The referenced <glyph>
is rendered as an alternate glyph.<image>
<image>
element, the xlink:href
attribute is animatable.<mpath>
<path>
element which defines the motion path.<pattern>
<pattern>
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 xlink:href
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 xlink:href
attribute, then the current element can inherit those attributes or children. On the <pattern>
element, the xlink:href
attribute is animatable.<script>
<textPath>
<path>
element onto which the text will be rendered. On the <textPath>
element, the xlink:href
attribute is animatable.<use>
<use>
element, the xlink:href
attribute is animatable.<tref>
<tref>
element. On the <tref>
element, the xlink:href
attribute is animatable.
© 2005–2017 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/xlink:href