SVG provides an 'a' element, analogous to HTML's 'a' element, to indicate links (also known as hyperlinks or Web links). SVG uses XLink ([XLink]) for all link definitions.
SVG 1.0 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 a URI specified by the XLink 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"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg width="5cm" height="3cm" viewBox="0 0 5 3" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <desc>Example link01 - a link on an ellipse </desc> <rect x=".01" y=".01" width="4.98" height="2.98" fill="none" stroke="blue" stroke-width=".03"/> <a xlink:href="http://www.w3.org"> <ellipse cx="2.5" cy="1.5" rx="2" ry="1" fill="red" /> </a> </svg>
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.
<!ENTITY % SVG.a.extra.content "" > <!ENTITY % SVG.a.element "INCLUDE" > <![%SVG.a.element;[ <!ENTITY % SVG.a.content "( #PCDATA | %SVG.Description.class; | %SVG.Animation.class; %SVG.Structure.class; %SVG.Conditional.class; %SVG.Image.class; %SVG.Style.class; %SVG.Shape.class; %SVG.Text.class; %SVG.Marker.class; %SVG.ColorProfile.class; %SVG.Gradient.class; %SVG.Pattern.class; %SVG.Clip.class; %SVG.Mask.class; %SVG.Filter.class; %SVG.Cursor.class; %SVG.Hyperlink.class; %SVG.View.class; %SVG.Script.class; %SVG.Font.class; %SVG.a.extra.content; )*" > <!ELEMENT %SVG.a.qname; %SVG.a.content; > <!-- end of SVG.a.element -->]]> <!ENTITY % SVG.a.attlist "INCLUDE" > <![%SVG.a.attlist;[ <!ATTLIST %SVG.a.qname; %SVG.Core.attrib; %SVG.Conditional.attrib; %SVG.Style.attrib; %SVG.Presentation.attrib; %SVG.GraphicalEvents.attrib; %SVG.XLinkReplace.attrib; %SVG.External.attrib; transform %TransformList.datatype; #IMPLIED target %LinkTarget.datatype; #IMPLIED > |
Attribute definitions:
On the Internet, resources are identified using URIs (Uniform Resource Identifiers) [URI]. For example, an SVG file called MyDrawing.svg located at http://example.com might have the following URI:
http://example.com/MyDrawing.svg
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:
http://example.com/MyDrawing.svg#Lamppost
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.
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 defines the meaning of the "selector" or "fragment identifier" portion of URIs that locate resources of MIME media type "image/svg+xml".
An SVG fragment identifier can come in three forms:
An SVG fragment identifier is defined as follows:
SVGFragmentIdentifier ::= BareName | XPointerIDRef | SVGViewSpec BareName ::= XML_Name SVGViewSpec ::= 'svgView(' SVGViewAttributes ')' SVGViewAttributes ::= SVGViewAttribute | SVGViewAttribute ';' SVGViewAttributes SVGViewAttribute ::= viewBoxSpec | preserveAspectRatioSpec | transformSpec | zoomAndPanSpec | viewTargetSpec viewBoxSpec ::= 'viewBox(' ViewBoxParams ')' preserveAspectRatioSpec = 'preserveAspectRatio(' AspectParams ')' transformSpec ::= 'transform(' TransformParams ')' zoomAndPanSpec ::= 'zoomAndPan(' ZoomAndPanParams ')' viewTargetSpec ::= 'viewTarget(' ViewTargetParams ')'
where:
xpointer(id('MyView'))
.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 link into an SVG document via an HTML [HTML4] anchor 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:
<!ENTITY % SVG.view.extra.content "" > <!ENTITY % SVG.view.element "INCLUDE" > <![%SVG.view.element;[ <!ENTITY % SVG.view.content "( %SVG.Description.class; %SVG.view.extra.content; )*" > <!ELEMENT %SVG.view.qname; %SVG.view.content; > <!-- end of SVG.view.element -->]]> <!ENTITY % SVG.view.attlist "INCLUDE" > <![%SVG.view.attlist;[ <!ATTLIST %SVG.view.qname; %SVG.Core.attrib; %SVG.External.attrib; viewBox %ViewBoxSpec.datatype; #IMPLIED preserveAspectRatio %PreserveAspectRatioSpec.datatype; 'xMidYMid meet' zoomAndPan ( disable | magnify ) 'magnify' viewTarget CDATA #IMPLIED > |
Attribute definitions:
Elements | Attributes | Content Model |
---|---|---|
a | Core.attrib, Conditional.attrib, Style.attrib, transform, target, GraphicalEvents.attrib, Presentation.attrib, External.attrib, XLinkReplace.attrib | (#PCDATA | Structure.class | Description.class Shape.class | Image.class | | View.class | Conditional.class | HyperinkingElements | Font.class | Script.class | Style.class | Marker.class | Clip.class | Mask.class | Gradient.class | Pattern.class | Filter.class | Cursor.class | Animation.class | ColorProfile.class)* |
The Hyperlinking Module defines the Hyperlink.class content set.
Content Set Name | Elements in Content Set |
---|---|
Hyperlink.class | a |
The XLink Attribute Module defines the XLink.attrib, XLinkRequired.attrib, XLinkEmbed.attrib and XLinkReplace.attrib attribute sets.
Collection Name | Attributes in Collection |
---|---|
XLink.attrib | xlink:type, xlink:href, xlink:role, xlink:arcrole, xlink:title, xlink:show, xlink:actuate |
XLinkRequired.attrib | xlink:type, xlink:href, xlink:role, xlink:arcrole, xlink:title, xlink:show, xlink:actuate |
XLinkEmbed.attrib | xlink:type, xlink:href, xlink:role, xlink:arcrole, xlink:title, xlink:show, xlink:actuate |
XLinkReplace.attrib | xlink:type, xlink:href, xlink:role, xlink:arcrole, xlink:title, xlink:show, xlink:actuate |
The ExternalResourcesRequired Attribute Module defines the External.attrib attribute set.
Collection Name | Attributes in Collection |
---|---|
External.attrib | externalResourcesRequired |
Elements | Attributes | Content Model |
---|---|---|
view | Core.attrib, External.attrib, viewBox, preserveAspectRatio, zoomAndPan, viewTarget | (Description.class) |
The View Module defines the View.class content set.
Content Set Name | Elements in Content Set |
---|---|
View.class | view |
The following interfaces are defined below: SVGAElement, SVGViewElement.
The SVGAElement interface corresponds to the 'a' element.
interface SVGAElement : SVGElement, SVGURIReference, SVGTests, SVGLangSpace, SVGExternalResourcesRequired, SVGStylable, SVGTransformable, events::EventTarget { readonly attribute SVGAnimatedString target; };
The SVGViewElement interface corresponds to the 'view' element.
interface SVGViewElement : SVGElement, SVGExternalResourcesRequired, SVGFitToViewBox, SVGZoomAndPan { readonly attribute SVGStringList viewTarget; };