|
|
Donner SVG Editor & Engine
SVG-native editor and embeddable SVG2 + CSS3 engine in C++20, with GPU (WebGPU) and compact CPU renderers, built for correctness, security, and performance.
|
<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 referenced element's preserveAspectRatio attribute decides how that 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?"
Donner parses preserveAspectRatio on the referenced <symbol> or <svg>, not on the <use> element itself. Put the fitting mode on the element being reused.
The attribute is a pair: <align> <meetOrSlice>.
The default is xMidYMid meet.
All three instances reference square symbols (viewBox="0 0 100 100") and are sized into a wider 120×60 rectangle (dashed outline). Only the referenced symbol's preserveAspectRatio differs:
Note: the referenced element's preserveAspectRatio only has an effect when that element has an intrinsic coordinate system (a viewBox). Referencing a bare <circle> or <path> does not create a fitted viewport.
| 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. |