SVG 'tref' element

The <tref> element is used to reference the text that is defined within the <defs> element. All character data within the referenced element, including character data enclosed within additional markup, will be rendered. You can use the referenced text multiple times in your SVG image, without having it included into the code more than once. The <tref> element has the following attributes:

  • xlink:href
  • attribute defines a URI reference to a fragment within an SVG document.

Here is a simple example:

<svg xmlns="http://www.w3.org/2000/svg" version="1.0"
xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<text id="Textref">
The text to be referenced to
</text>
</defs>

<text x="20" y="20" font-size="48" fill="#9d1d20" >
Inline text
</text>

<text x="20" y="40" font-size="48" fill="red" style="text-decoration:underline;">
<tref xlink:href="#Textref"/>
</text>
</svg>

Here is the resulting text: