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 August 1999//EN" "http://www.w3.org/Graphics/SVG/SVG-19990812.dtd"> <svg width="4in" height="3in"> <desc>This valid svg document draws a triangle which is a hyperlink </desc> <a xlink:href="http://www.w3.org"> <path d="M 0 0 L 200 0 L 100 200 z"/> </a> </svg>
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-19990812.dtd'> <desc>This well formed svg document draws a triangle which is a hyperlink </desc> <a xmlns:xlink="http://www.w3.org/XML/XLink/0.9" xlink:type="simple" xlink:show="replace" xlink:actuate="user" xlink:href="http://www.w3.org"> <path d="M 0 0 L 200 0 L 100 200 z"/> </a> </svg>
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.
<!ELEMENT a (defs?,desc?,title?, (path|text|rect|circle|ellipse|line|polyline|polygon| use|image|svg|g|switch|a)*)> <!ATTLIST a id ID #IMPLIED 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|parsed|replace) #FIXED 'replace' xlink:actuate (user|auto) #FIXED 'user' xlink:href CDATA #REQUIRED >
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 documents 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.
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 | SVGViewSpec BareName ::= XML_Name XPointerIDRef ::= 'xptr(id(' XML_Name '))' SVGViewSpec ::= 'svgView(' SVGViewAttributes ')' SVGViewAttributes ::= SVGViewAttribute | SVGViewAttribute ';' SVGViewAttributes SVGViewAttribute ::= viewBoxSpec | preserveAspectRatioSpec | transformSpec | allowZoomAndPanSpec | viewTargetSpec 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 ::= 'allowZoomAndPanSpec(' TrueOrFalse ')' TrueOrFalse ::= 'true' | 'false' viewTargetSpec ::= 'viewTarget(' XML_Name ')'
Spaces are not allowed in fragment specifications; thus, commas should be used to separate numeric values within an SVG view specification (e.g., #svgView(viewBox(0,0,200,200))) and semicolons should be 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:
The <view> element is defined as follows:
<!ELEMENT view (desc?,title?) <!ATTLIST view id ID #IMPLIED viewBox CDATA #IMPLIED preserveAspectRatio CDATA 'xMidYMid meet' allowZoomAndPan (true | false) "true" viewTarget CDATA #IMPLIED >