The <use>
element takes nodes from within the SVG document, and duplicates them somewhere else.
<svg viewBox="0 0 30 10" xmlns="http://www.w3.org/2000/svg"> <circle id="myCircle" cx="5" cy="5" r="4"/> <use href="#myCircle" x="10" fill="blue"/> <use href="#myCircle" x="20" fill="white" stroke="blue"/> </svg>
The effect is the same as if the nodes were deeply cloned into a non-exposed DOM, and then pasted where the use
element is, much like cloned template elements in HTML5. Since the cloned nodes are not exposed, care must be taken when using CSS to style a use
element and its hidden descendants. CSS attributes are not guaranteed to be inherited by the hidden, cloned DOM unless you explicitly request it using CSS inheritance.
For security reasons, some browsers could apply a same-origin policy on use
elements and could refuse to load a cross-origin URI within the href
attribute.
Since SVG 2, the xlink:href
attribute is deprecated in favor of simply href
. See xlink:href
page for more information.
href
x
0
; Animatable: yes
y
0
; Animatable: yes
width
0
; Animatable: yes
height
0
; Animatable: yes
Note: Starting with SVG2 x
, y, width
and height
are Geometry Properties, meaning those attributes can also be used as CSS properties for that element.
id
, tabindex
class
, style
requiredExtensions
, systemLanguage
clip-path
, clip-rule
, color
, color-interpolation
, color-rendering
, cursor
, display
, fill
, fill-opacity
, fill-rule
, filter
, mask
, opacity
, pointer-events
, shape-rendering
, stroke
, stroke-dasharray
, stroke-dashoffset
, stroke-linecap
, stroke-linejoin
, stroke-miterlimit
, stroke-opacity
, stroke-width
, transform
, vector-effect
, visibility
aria-activedescendant
, aria-atomic
, aria-autocomplete
, aria-busy
, aria-checked
, aria-colcount
, aria-colindex
, aria-colspan
, aria-controls
, aria-current
, aria-describedby
, aria-details
, aria-disabled
, aria-dropeffect
, aria-errormessage
, aria-expanded
, aria-flowto
, aria-grabbed
, aria-haspopup
, aria-hidden
, aria-invalid
, aria-keyshortcuts
, aria-label
, aria-labelledby
, aria-level
, aria-live
, aria-modal
, aria-multiline
, aria-multiselectable
, aria-orientation
, aria-owns
, aria-placeholder
, aria-posinset
, aria-pressed
, aria-readonly
, aria-relevant
, aria-required
, aria-roledescription
, aria-rowcount
, aria-rowindex
, aria-rowspan
, aria-selected
, aria-setsize
, aria-sort
, aria-valuemax
, aria-valuemin
, aria-valuenow
, aria-valuetext
, role
xlink:href
, xlink:title
Categories | Graphics element, Graphics referencing element, Structural element |
---|---|
Permitted content | Any number of the following elements, in any order: Animation elements Descriptive elements |
Specification | Status | Comment |
---|---|---|
Scalable Vector Graphics (SVG) 2 The definition of '<use>' in that specification. | Candidate Recommendation | |
Scalable Vector Graphics (SVG) 1.1 (Second Edition) The definition of '<use>' in that specification. | Recommendation | Initial definition |
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | 22 | 12 | 4
|
Yes | 11.5 | 3 |
Load from external URI | 22 | 13 | 4 | No | 11.5 | 6.1 |
Load from data: URI |
22 | Yes | 4 | No | 11.5 | 5.1 |
href |
Yes | Yes | Yes | Yes | Yes | No |
xlink:href
|
Yes | Yes | Yes | Yes | Yes | Yes |
x |
Yes | Yes | Yes | Yes | Yes | Yes |
y |
Yes | Yes | Yes | Yes | Yes | Yes |
height |
Yes | Yes | Yes | Yes | Yes | Yes |
width |
Yes | Yes | Yes | Yes | Yes | Yes |
Mobile | |||||||
---|---|---|---|---|---|---|---|
Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
Basic support | 4 | Yes | 12 | 4
|
11.5 | 3 | ? |
Load from external URI | 4.4 | Yes | 13 | 4 | 11.5 | 6.1 | ? |
Load from data: URI |
4 | Yes | Yes | 4 | 11.5 | 5.1 | ? |
href |
Yes | Yes | Yes | Yes | Yes | No | ? |
xlink:href
|
Yes | Yes | Yes | Yes | Yes | Yes | ? |
x |
Yes | Yes | Yes | Yes | Yes | Yes | ? |
y |
Yes | Yes | Yes | Yes | Yes | Yes | ? |
height |
Yes | Yes | Yes | Yes | Yes | Yes | ? |
width |
Yes | Yes | Yes | Yes | Yes | Yes | ? |
© 2005–2018 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/Element/use