The <image>
SVG element includes images inside SVG documents. It can display raster image files or other SVG files.
The only image formats SVG software must support are JPEG, PNG, and other SVG files. Animated GIF behavior is undefined.
SVG files displayed with <image>
are treated as an image: external resources aren't loaded, :visited styles aren't applied, and they cannot be interactive. To include dynamic SVG elements, try <use> with an external URL. To include SVG files and run scripts inside them, try <object> inside of <foreignObject>.
Note: The HTML spec defines <image>
as a synonym for <img> while parsing HTML. This specific element and its behavior only apply inside SVG documents or inline SVG.
Categories | Graphics element, Graphics referencing element |
---|---|
Permitted content | Any number of the following elements, in any order: Animation elements Descriptive elements |
class
style
externalResourcesRequired
transform
x
: Positions the image horizontally from the origin.y
: Positions the image vertically from the origin.width
: The width the image renders at. Unlike HTML's <img>
, this attribute is required.height
: The height the image renders at. Unlike HTML's <img>
, this attribute is required.xlink:href
: Points at a URL for the image file.preserveAspectRatio
: Controls how the image is scaled.<image>
implements the SVGImageElement
interface.
Basic rendering of a PNG image in SVG:
<svg viewBox="0 0 100 100"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink">
<image href="https://mdn.mozillademos.org/files/6457/mdn_logo_only_color.png" height="100" width="100"/>
</svg>
Specification | Status | Comment |
---|---|---|
Scalable Vector Graphics (SVG) 2 The definition of '<image>' in that specification. | Candidate Recommendation | Allows omitting height and width
|
Scalable Vector Graphics (SVG) 1.1 (Second Edition) The definition of '<image>' in that specification. | Recommendation | Initial definition |
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|---|
Basic support | 1.0 | (Yes) | 1.5 (1.8) | 9.0 | 8.0 | 3.0.4 |
Feature | Android | Edge | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | 3.0 | (Yes) | 1.0 (1.8)[1] | No support | (Yes) | 3.0.4 |
The chart is based on these sources.
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/SVG/Element/image