Note xlink:href
has been deprecated, just use href
instead, e.g.
<svg viewBox="0 0 512 512">
<image width="512" height="512" href="external.svg"/>
</svg>
viewBox
, width
and height
values (in this answer) are simply for illustration purpose, adjust the layout accordingly (read more).
Since <image>
shares similar spec as <img>
, meaning it doesn't support SVG styling, as mentioned in Christiaan's answer. For example, if I have the following css line that set the svg shape color to be the same as the font color,
svg {
fill: currentColor;
}
The above style wouldn't apply if <image>
is used. For that, you need to use <use>
, as shown in Nick's answer.
Note id="layer1"
and href="OTHERFILE.svg#layer1"
values in his answer are mandatory.
Meaning you have to add the id
attribute to the external svg file, so you need to host the (modified) external svg file by yourself (your website) or somewhere else. The resulting external svg file looks like this (notice where I put the id
):
<svg id="logo" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
<path d="..."/>
</svg>
The value of id can be anything, I use "logo" in this example.
To embed that svg,
<svg viewBox="0 0 512 512">
<use href="edited-external.svg#logo"/>
</svg>
If you use the above svg as inline in your html, you don't need xmlns attribute (at least what I know from svgo).