SVG 2 – 09 July 2015 TopContentsPreviousNextElementsAttributesProperties

Chapter 15: Linking


15.1. References

15.1.1. Overview

On the Internet, resources are identified using URLs (Internationalized Resource Identifiers). For example, an SVG file called someDrawing.svg located at might have the following URL:

An URL can also address a particular element within an XML document by including an URL fragment identifier as part of the URL. An URL which includes an URL fragment identifier consists of an optional base URL, followed by a "#" character, followed by the URL fragment identifier. For example, the following URL can be used to specify the element whose ID is "Lamppost" within file someDrawing.svg:

15.1.2. URLs and URIs

Internationalized Resource Identifiers (URLs) are a more generalized complement to Uniform Resource Identifiers (URIs). An URL is a sequence of characters from the Universal Character Set [UNICODE]. A URI is constructed from a much more restricted set of characters. All URIs are already conformant URLs. A mapping from URLs to URIs is defined by the URL specification, which means that URLs can be used instead of URIs in XML documents, to identify resources. URLs can be converted to URIs for resolution on a network, if the protocol does not support URLs directly.

Previous versions of SVG, following XLink, defined an URL reference type as a URI or as a sequence of characters which must result in an URL after a particular escaping procedure was applied. The escaping procedure was repeated in the XLink 1.0 specification [XLINK], and in the W3C XML Schema Part 2: Datatypes specification [SCHEMA2]. This copying introduced the possibility of error and divergence, but was done because the URL specification was not yet standardized.

In this specification, the correct term URL is used for this "URI or sequence of characters plus an algorithm" and the escaping method, which turns URLs into URIs, is defined by reference to the URL specification [RFC3987], which has since become an IETF Proposed Standard. Other W3C specifications are expected to be revised over time to remove these duplicate descriptions of the escaping procedure and to refer to URL directly.

15.1.3. Syntactic forms: URL and <url>

In most cases, URLs are specified using an ‘href’ attribute. However, some attributes allow both URLs and text strings as content. To disambiguate a text string from a relative URL, the <url> production is used [CSS3VALUES]. This is simply a URL delimited with a functional notation. This form is used in presentation attributes.

SVG makes extensive use of URL 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 id="MyGradient">...</linearGradient>

You then reference the linear gradient as the value of the ‘fill’ property for the rectangle, as in the following example:

<rect fill="url(#MyGradient)"/>

SVG supports two types of URL references:

15.1.4. Processing of URL references

The following list describes the elements and properties that allow URL references and the valid target types for those references:

The following rules apply to the processing of invalid URL references:

15.1.5. URL reference attributes

URL references are normally specified with an ‘href’ attribute. The value of this attribute forms a reference for the desired resource (or secondary resource, if there is a fragment identifier). The value of the ‘href’ attribute must be a URL.

Because it is impractical for any application to check that a value is an URL reference, this specification follows the lead of the URL Specification in this matter and imposes no such conformance testing requirement on SVG applications.

If the URL reference is relative, its absolute version must be computed by the method described in XML Base before use [XML-BASE].

If the protocol, such as HTTP, does not support URLs directly, the URL is converted to a URI by the SVG implementation, as described in section 3.1 of the URL specification [RFC3987].

15.1.6. Deprecated XLink URL reference attributes

In previous versions of SVG, the ‘href’ attribute was specified in the XLink namespace [XLINK] namespace. This usage is now deprecated and instead URL references should be specified using the ‘href’ attribute without a namespace.

For backwards compatibility, the deprecated xlink:href attribute is defined below along with the xlink:title attribute which has also been deprecated.

Attribute definitions:

Name Value Initial value Animatable
xlink:href URL [URL] (none) (see below)

For backwards compatibility, elements with an ‘href’ attribute also recognize an ‘href’ attribute in the XLink namespace [XLINK].

When the ‘href’ attribute is present in both the the XLink namespace and without a namespace, the value of the attribute without a namespace shall be used. The attribute in the XLink namespace shall be ignored.

A Conforming SVG Generator must generate ‘href’ attributes without a namespace. However, it may also generate ‘href’ attributes in the XLink namespace to provide backwards compatibility.

This attribute is Animatable if and only if the corresponding ‘href’ attribute is defined to be animatable.

Name Value Initial value Animatable
xlink:title <anything> (none) no

Deprecated attribute to describe the meaning of a link or resource in a human-readable fashion. New content should use a ‘title’ child element rather than a ‘xlink:title’ attribute.

The use of this information is highly dependent on the type of processing being done. It may be used, for example, to make titles available to applications used by visually impaired users, or to create a table of links, or to present help text that appears when a user lets a mouse pointer hover over a starting resource.

The ‘title’ attribute, if used, must be in the XLink namespace. Refer to the XML Linking Language (XLink) [XLINK].

When using the deprecated XLink attributes xlink:href or xlink:title an explicit XLink namespace declaration must be provided [XML-NS], One simple way to provide such an XLink namespace declaration is to include an ‘xmlns’ attribute for the XLink namespace on the svg element for content that uses XLink attributes. For example:

<svg xmlns:xlink="" ...>
  <image xlink:href="foo.png" .../>

SVG provides an a element, to indicate links (also known as hyperlinks or Web links). The a element may contain any element that its parent may contain, except itself.

SVG uses XLink ([XLink]) for all link definitions. SVG 1.1 only requires that user agents support XLink's notion of simple links. Each simple link associates exactly two resources, one local and one remote, with an arc going from the former to the latter.

A simple link is defined for each separate rendered element contained within the a element; thus, if the a element contains three circle elements, a link is created for each circle. For each rendered element within an a element, the given rendered element is the local resource (the source anchor for the link).

The remote resource (the destination for the link) is defined by an URL specified by the href attribute on the a element. The remote resource may be any Web resource (e.g., an image, a video clip, a sound bite, a program, another SVG document, an HTML document, an element within the current document, an element within a different document, etc.). By activating these links (by clicking with the mouse, through keyboard input, voice commands, etc.), users may visit these resources.

Example link01 assigns a link to an ellipse.

<?xml version="1.0" standalone="no"?>
<svg width="5cm" height="3cm" viewBox="0 0 5 3" version="1.1"
  <desc>Example link01 - a link on an ellipse
  <rect x=".01" y=".01" width="4.98" height="2.98" 
        fill="none" stroke="blue"  stroke-width=".03"/>
  <a href="">
    <ellipse cx="2.5" cy="1.5" rx="2" ry="1"
             fill="red" />
Example link01 — a link on an ellipse

Example link01

View this example as SVG (SVG-enabled browsers only)

If the above SVG file is viewed by a user agent that supports both SVG and HTML, then clicking on the ellipse will cause the current window or frame to be replaced by the W3C home page.

Container element
Content model:
Any number of the following elements or character data, in any order:a, clipPath, cursor, filter, foreignObject, image, marker, mask, script, style, switch, text, view
DOM Interfaces:

Attribute definitions:

Name Value Initial value Animatable
href URL [URL] (none) yes
The location of the referenced object, expressed as an URL reference. Refer to the common handling defined for URL reference attributes.
Name Value Initial value Animatable
target _self | _parent | _top | _blank | <XML-Name> _self yes

Should the remaining differences with the "valid browsing context name or keyword" definition from HTML be harmonized? Specifically: HTML keywords are case-insensitive; HTML allows any string that doesn't start with "_" as a custom name, (requiring an XML name is more restrictive).

This attribute should be used when there are multiple possible targets for the ending resource, such as when the parent document is embedded within an HTML or XHTML document, or is viewed with a tabbed browser. This attribute specifies the name of the browsing context (e.g., a browser tab or an SVG, HTML, or XHTML iframe or object element) into which a document is to be opened when the link is activated:

The current SVG image is replaced by the linked content in the same browsing context as the current SVG image.
The immediate parent browsing context of the SVG image is replaced by the linked content, if it exists and can be securely accessed from this document.
The content of the full active window or tab is replaced by the linked content, if it exists and can be securely accessed from this document
A new un-named window or tab is requested for the display of the linked content, if this document can securely do so. If the user agent does not support multiple windows/tabs, the result is the same as _top.
Specifies the name of the browsing context (tab, inline frame, object, etc.) for display of the linked content. If a context with this name already exists, and can be securely accessed from this document, it is re-used, replacing the existing content. If it does not exist, it is created (the same as '_blank', except that it now has a name). The name must be a valid XML Name [XML11], and should not start with an underscore (U+005F LOW LINE character), to meet the requirements of a valid browsing context name from HTML.

The normative definitions for browsing contexts and security restrictions on navigation actions between browsing contexts is HTML 5 [HTML], specifically the chapter on loading web pages.

Previous versions of SVG defined the special target value '_replace'. It was never well implemented, and the distinction between '_replace' and '_self' has been made redundant by changes in the HTML definition of browsing contexts. Use '_self' to replace the current SVG document.

The value '_new' is not a legal value for target. Use '_blank' to open a document in a new tab/window.

15.3. Linking into SVG content: URL fragments and SVG views

Because SVG content often represents a picture or drawing of something, a common need is to link into a particular view of the document, where a view indicates the initial transformations so as to present a closeup of a particular section of the document.

15.3.1. SVG fragment identifiers

SVG 2 Requirement: Merge the SVG 1.1 SE text and the SVG Tiny 1.2 text on fragment identifiers link traversal and add media fragments.
Resolution: SVG 2 will have media fragment identifiers.
Purpose: To align with Media Fragments URI.
Owner: Cyril (ACTION-3442)

To link into a particular view of an SVG document, the URL fragment identifier needs to be a correctly formed SVG fragment identifier. An SVG fragment identifier defines the meaning of the "selector" or "fragment identifier" portion of URLs that locate resources of MIME media type "image/svg+xml".

An SVG fragment identifier can come in the following forms:

An SVG fragment identifier is defined as follows:

SVGFragmentIdentifier ::= BareName *( "&" timesegment ) |
                          SVGViewSpec *( "&" timesegment ) |
                          spacesegment *( "&" timesegment ) |
                          timesegment *( "&" spacesegment )

BareName ::= XML_Name
SVGViewSpec ::= 'svgView(' SVGViewAttributes ')'
SVGViewAttributes ::= SVGViewAttribute |
                      SVGViewAttribute ';' SVGViewAttributes

SVGViewAttribute ::= viewBoxSpec |
                     preserveAspectRatioSpec |
                     transformSpec |
                     zoomAndPanSpec |
viewBoxSpec ::= 'viewBox(' ViewBoxParams ')'
preserveAspectRatioSpec = 'preserveAspectRatio(' AspectParams ')'
transformSpec ::= 'transform(' TransformParams ')'
zoomAndPanSpec ::= 'zoomAndPan(' ZoomAndPanParams ')'
viewTargetSpec ::= 'viewTarget(' ViewTargetParams ')'


Spaces are not allowed in fragment specifications; thus, commas are used to separate numeric values within an SVG view specification (e.g., #svgView(viewBox(0,0,200,200))) and semicolons are used to separate attributes (e.g., #svgView(viewBox(0,0,200,200);preserveAspectRatio(none))).

Semicolons used to separate 'SVGViewAttribute' in SVG fragments may be url-escaped (as %3B); this is useful when animating a (semi-colon separated) list of URLs because otherwise the semicolon would be interpreted as a list separator.

The previous two paragraphs do not reflect actual browser support (spaces are usually supported, commas and URL escaping not always).

The five types of SVGViewAttribute may occur in any order, but each type may only occur at most one time in a correctly formed SVGViewSpec.

When a source document performs a link into an SVG document, for example via an HTML anchor element ([HTML4], section 12.2; i.e., <a href=...> element in HTML) or an XLink specification [XLINK], then the SVG fragment identifier specifies the initial view into the SVG document, as follows:

15.3.2. Predefined views: the ‘view’ element

The ‘view’ element is defined as follows:

Content model:
Any number of the following elements, in any order:script
DOM Interfaces:

Attribute definitions:

Name Value Initial value Animatable
viewTarget (see below) (none) no
Indicates the target object associated with the view. This attribute must be any value other than the empty string.
Define the expected effect of declaring a 'viewTarget', here or in an svgView target fragment.

15.3.3. Highlighting views

This section and example needs to be updated subject to a decision on whether 'viewTarget' should cause a match to the ':target' pseudoclass.

It is helpful to users if the target element(s) are highlighted. The visual styling of this highlight should be decided by the document author, because the SVG user agent has no way to determine what changes would make the elements more visible.

The CSS :target selector ([SELECTORS], section 6.2.2) may be used in a stylesheet to provide alternate styling for elements which are the target of links. For example:

<style type="text/css">
#foo:target {filter: url(#glow)}
/* when the element with id foo is linked to, use a glow filter */

.bar :target {stroke: green; fill-opacity: 0.5}
/* when any descendants of elements with class bar are linked
   to, make the fill partly transparent and use a green stroke */

:target {stroke: red }
/* for everything else, just use a red stroke */ 

15.4. DOM interfaces

15.4.1. Interface SVGAElement

The SVGAElement interface corresponds to the a element.

interface SVGAElement : SVGGraphicsElement {
  readonly attribute SVGAnimatedString target;

SVGAElement implements SVGURIReference;
target (readonly SVGAnimatedString)
Corresponds to attribute target on the given a element.

15.4.2. Interface SVGViewElement

The SVGViewElement interface corresponds to the view element.

interface SVGViewElement : SVGElement {
  readonly attribute SVGStringList viewTarget;

SVGViewElement implements SVGFitToViewBox;
SVGViewElement implements SVGZoomAndPan;
viewTarget (readonly SVGStringList)
Corresponds to attribute viewTarget on the given view element. A list of DOMString values which contain the names listed in the viewTarget attribute. Each of the DOMString values can be associated with the corresponding element using the getElementById() method call.
SVG 2 – 09 July 2015 TopContentsPreviousNextElementsAttributesProperties