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" />

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.

Leave a Comment

Posting Code!

You may write comments in Markdown. This makes code easy to post, as you can write inline code like `<div>this</div>` or multiline blocks of code in triple backtick fences (```) with double new lines before and after.

Code of Conduct

Absolutely anyone is welcome to submit a comment here. But not all comments will be posted. Think of it like writing a letter to the editor. All submitted comments will be read, but not all published. Published comments will be on-topic, helpful, and further the discussion or debate.

Want to tell us something privately?

Feel free to use our contact form. That's a great place to let us know about typos or anything off-topic.