htmlcsssvg

Request part of SVG in <img> (or <object>)


Could I load only part of a SVG (that could be identified by an #id tag) in an <img> or <object> tag ?

Reason (if I need one) is I don't want to have two SVG files if I'm only using part of a already in use one.

If I can't by using these tags, could I by using CSS or other means ?


Solution

  • What you want to achieve is easiest done with another inline SVG instead of a <img> or <object> tag:

    <svg style="width:200px;height:200px" viewBox="35 50 150 150">
        <use xlink:href="myFile.svg#head" />
    </svg>
    

    Two things you need to get right are