Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include SVG file in SVG

Tags:

include

svg

I've got a linearGradient in the defs section of my SVG file, and reference it with fill="url(#myGradientName)". That works great so far.

I think I should be able to put my whole defs section in its own SVG file, and then just reference that from all my SVG images. That is, something like:

styles.svg:

<svg xmlns=...>
  <defs>
    <linearGradient id="myGradient" ...>
    </linearGradient>
  </defs>
</svg>

image.svg:

<svg xmlns=...>
  <rect width="100" height="100" fill="styles.svg#myGradient"/>
</svg>

But I can't seem to get the style to apply. Do I have the wrong syntax for IDs external to this file (styles.svg#myGradient)? Do I need to explicitly include the file first somehow?

I've been pouring over the SVG spec and it looks like this should be possible, but none of the examples actually show it being done.

Edit: The FOP FAQ suggests that the correct syntax is fill="url(grad.svg#PurpleToWhite)", but that doesn't work in Gecko or Webkit. Is that correct and nobody supports it, or am I doing something else wrong?

like image 404
Ken Avatar asked Mar 16 '09 20:03

Ken


People also ask

Can you embed an SVG in an SVG?

The SVG format allows for the nesting of SVG graphics. It is possible for an “<svg>” elements, to be placed within another “<svg>” element.

How do I combine multiple SVGs?

First, upload the SVGs using the above button or drag and drop them directly to the editor to combine multiple SVG images. Once uploaded, place the SVG images together either vertically, horizontally, or at any position. Lastly, download the merged SVG image in multiple file formats.

How do I embed an image in SVG?

3. How to use inline SVG images. SVG images can be written directly into the HTML document using the <svg> </svg> tag. To do this, open the SVG image in VS code or your preferred IDE, copy the code, and paste it inside the <body> element in your HTML document.


1 Answers

It looks like this is only supported under Firefox 3.1.

like image 159
Ken Avatar answered Oct 26 '22 00:10

Ken