17 Linking



17.1 Links out of SVG content: the 'a' element

SVG provides an 'a' element, analogous to like HTML's 'a' element, to indicate hyperlinks; those parts of the drawing which when clicked on will cause the current browser frame to be replaced by the contents of the URL specified in the href attribute.

The 'a' element uses Xlink. (Note that the XLink specification is currently under development and is subject to change. The SVG working group will track and rationalize with XLink as it evolves.)

The following is a valid example of a hyperlink attached to a path (which in this case draws a triangle):

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG December 1999//EN" 
<svg width="4in" height="3in">
  <desc>This valid svg document draws a triangle which is a hyperlink
  <a xlink:href="http://www.w3.org">
    <path d="M 0 0 L 200 0 L 100 200 z"/>

Download this example

This is the well-formed equivalent example:

<?xml version="1.0" standalone="yes"?>
<svg width="4in" height="3in"
 xmlns = 'http://www.w3.org/Graphics/SVG/SVG-19991203.dtd'>
  <desc>This well formed svg document draws a triangle which is a hyperlink
  <a xmlns:xlink="http://www.w3.org/XML/XLink/0.9" 
     xlink:type="simple" xlink:show="replace" xlink:actuate="user" 
    <path d="M 0 0 L 200 0 L 100 200 z"/>

Download this example

In both examples, if the path is clicked on, then the current browser frame will be replaced by the W3C home page.
<!ENTITY % aExt "" >
<!ELEMENT a (%descTitleDefs;,
                   %ceExt;%aExt;)*) >
  xmlns:xlink CDATA #FIXED "http://www.w3.org/XML/XLink/0.9"
  xlink:type (simple|extended|locator|arc) #FIXED "simple" 
  xlink:role CDATA #IMPLIED
  xlink:title CDATA #IMPLIED
  xlink:show (new|embed|replace) 'replace'
  xlink:actuate (user|auto) #FIXED 'user'
  xlink:href CDATA #REQUIRED
  target CDATA #IMPLIED >

xmlns [:prefix] = "resource-name"
Standard XML attribute for identifying an XML namespace. This attribute makes the XLink [XLink] namespace available to the current element. Refer to the "Namespaces in XML" Recommendation [XML-NS].
Animatable: no.
xlink:type = 'simple'
Identifies the type of XLink being used. For hyperlinks in SVG, only simple links are available. Refer to the "XML Linking Language (XLink)" [XLink].
Animatable: no.
xlink:role = '<string>'
A generic string used to describe the function of the link's content. Refer to the "XML Linking Language (XLink)" [XLink].
Animatable: no.
xlink:title = '<string>'
Human-readable text describing the link. Refer to the "XML Linking Language (XLink)" [XLink].
Animatable: no.
xlink:show = 'replace'
Indicates that upon activation of the link the referenced document will. replace the entire contents of the current document. Refer to the "XML Linking Language (XLink)" [XLink].
Animatable: no.
xlink:actuate = 'user'
Indicates that the contents of the referenced object are incorporated into the current document upon user action. Refer to the "XML Linking Language (XLink)" [XLink].
Animatable: no.
xlink:href = "<uri>"
The location of the referenced object, expressed as a URI reference. Refer to the "XML Linking Language (XLink)" [XLink].
Animatable: yes.
target = "<frame-target>"
This attribute has applicability when the current SVG document is used as part of an HTML [HTML40] or XHTML [XHTML10] parent document which defines multiple frames. This attribute specifies the name of an HTML or XHTML frame into which a document is to be opened when the hyperlink is activated. For more information, refer to the appropriate HTML or XHTML specifications.
Animatable: yes.

17.2 Linking into SVG content: URI fragments and SVG views

17.2.1 Introduction: URI fragments and SVG views

On the Internet, resources are identified using URIs (Uniform Resource Identifiers) [URI]. For example, an SVG file called MyDrawing.svg located at http://www.MyCompany.com might have the following URI:


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


Because SVG content often represent 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.

17.2.2 SVG fragment identifiers

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

An SVG fragment identifier can come in three forms:

An SVG fragment identifier is defined as follows:

SVGFragmentIdentifier ::= BareName |
                          XPointerIDRef |
BareName ::= XML_Name

XPointerIDRef ::= 'xptr(id(' XML_Name '))'

SVGViewSpec ::= 'svgView(' SVGViewAttributes ')'

SVGViewAttributes ::= SVGViewAttribute |
                      SVGViewAttribute ';' SVGViewAttributes
SVGViewAttribute ::= viewBoxSpec |
                     preserveAspectRatioSpec |
                     transformSpec |
                     enableZoomAndPanControlsSpec |

viewBoxSpec ::= 'viewBox(' X ',' Y ',' Width ',' Height ')'

X ::= Number

Y ::= Number

Width ::= Number

Height ::= Number

preserveAspectRatioSpec = 'preserveAspectRatio(' AspectParams ')'

AspectParams ::= AspectValue |
                 AspectValue ',' MeetOrSlice

AspectValue ::= 'none' | 'xMinYMin' | 'xMinYMid' | 'xMinYMax' |
                'xMidYMin' | 'xMidYMid' | 'xMidYMax' |
                'xMaxYMin' | 'xMaxYMid' | 'xMaxYMax'

MeetOrSlice ::= 'meet' | 'slice'

Height ::= Number

transformSpec ::= 'transform(' TransformParams ')'

transformSpec ::= 'enableZoomAndPanControls(' TrueOrFalse ')'

TrueOrFalse ::= 'true' | 'false'

viewTargetSpec ::= 'viewTarget(' XML_Name ')'


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))).

When a source document performs a hyperlink into an SVG document via an HTML [HTML40] linking element (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:

17.2.3 Predefined views: the 'view' element

The 'view' element is defined as follows:
<!ENTITY % viewExt "" >
<!ELEMENT view (%descTitle;%viewExt;) >
<!ATTLIST view
  preserveAspectRatio CDATA 'xMidYMid meet'
  enableZoomAndPanControls (true | false) "true" 
  viewTarget CDATA #IMPLIED >

Attribute definitions:

viewTarget = "XML_Name [XML_NAME]*"
Indicates the target object associated with the view. If provided, then the target element(s) will. be highlighted.
Animatable: no.

Attributes defined elsewhere:
class, viewBox, preserveAspectRatio, enableZoomAndPanControls.

17.3 DOM interfaces

17.3.1 Interface SVGAElement

The SVGAElement interface corresponds to the 'a' element.

interface SVGAElement : SVGElement {
  attribute DOMString role;
  attribute DOMString title;
  attribute DOMString show;
  attribute DOMString actuate;
  attribute DOMString href;
  attribute DOMString target;

17.3.2 Interface SVGViewSpec

This interface corresponds to an SVG View Specification.

interface SVGViewSpec {
  // Object-oriented access
  SVGRect viewBox;
  SVGPreserveAspectRatio preserveAspectRatio;
  SVGTransformList transform;
  boolean enableZoomAndPanControls;
  SVGElement viewTarget;

  // String-oriented access.
  // (Necessary because this information is part
  // of the original document and thus not available
  // in XML DOM.)
  DOMString viewBoxString;
  DOMString preserveAspectRatioString;
  DOMString transformString;
  DOMString enableZoomAndPanControlsString;
  DOMString viewTargetString;