31: You Can Put Raster Images in SVG

(Updated on )

There probably isn’t a tremendously huge use-case for this, other than the obvious: you need a raster graphic amongst other things in a larger SVG design. That way it moves and scales with the rest of the elements.

The syntax is:

<svg ... >
  <image xlink:href="/path/to/image.jpg" width="100%" height="100%" x="0" y="0" />
</svg>

You’d probably never drop a raster graphic in an SVG all by itself as there isn’t any advantages to it. Yes, you can apply SVG filters to the image then, but you can apply SVG filters to an <img> as well. Same goes for clipping paths and masks.

The filters can appear slightly different though, so good to be aware of that:

See the Pen SVG filters on SVG or IMG by Chris Coyier (@chriscoyier) on CodePen.