|
|
Donner 0.5.1
Embeddable browser-grade SVG2 engine
|
<use> instantiates another element at a specified position, cloning its rendered output.
It's the SVG equivalent of "put another copy of that shape over here" — commonly used for reusable icon libraries, tilesets, symbol sheets, and anywhere you'd otherwise copy-paste the same shape multiple times. Define your artwork once (typically inside <defs> or a <symbol>), then stamp it out wherever you need it with <use href="#id" x="..." y="..." />.
The cloned content inherits styles from the <use> element itself, so a single symbol can be re-coloured per instance by setting fill, stroke, etc. on each <use>. The clones remain linked to the referenced source and automatically reflect later DOM mutations to the original.
Define a circle once, then stamp a second instance at x="100" with a different fill:
A <symbol> is a template that isn't rendered on its own — it's only visible through a <use> reference. Symbols can declare their own viewBox, which makes them resolution independent: the <use> element's width and height decide how big the instance is, and the symbol's viewBox is mapped into that box:
When <use> references a <symbol> or nested <svg> element that has its own viewBox, the preserveAspectRatio attribute decides how the referenced content is fitted into the <use> element's width/height box. It answers the question: "when the symbol's intrinsic aspect ratio doesn't match the destination rectangle, should we stretch, letterbox, or crop?"
The attribute is a pair: <align> <meetOrSlice>.
The default is xMidYMid meet.
All three instances reference the same square <symbol> (viewBox="0 0 100 100") and are sized into a wider 120×60 rectangle (dashed outline). Only preserveAspectRatio differs:
Note: preserveAspectRatio only has an effect when the referenced element has an intrinsic coordinate system (a viewBox). Referencing a bare <circle> or <path> ignores it.
| Attribute | Default | Description |
|---|---|---|
| href | (none) | URI (typically #id) of the element to reuse. |
| x | 0 | X coordinate where the referenced element is placed. |
| y | 0 | Y coordinate where the referenced element is placed. |
| width | auto | Width of the instance. Only meaningful when the referenced element has a viewBox (e.g. <symbol> or <svg>). |
| height | auto | Height of the instance. Only meaningful when the referenced element has a viewBox. |
| preserveAspectRatio | xMidYMid meet | How the referenced content is fitted into width × height when aspect ratios differ. See above. |