-
Notifications
You must be signed in to change notification settings - Fork 22.4k
/
index.md
60 lines (39 loc) · 2.29 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
---
title: <image>
slug: Web/SVG/Element/image
page-type: svg-element
browser-compat: svg.elements.image
---
{{SVGRef}}
The **`<image>`** SVG element includes images inside SVG documents. It can display {{glossary("raster image")}} files or other SVG files.
The only image formats SVG software must support are {{glossary("JPEG")}}, {{glossary("PNG")}}, and other SVG files. Animated {{glossary("GIF")}} behavior is undefined.
SVG files displayed with `<image>` are [treated as an image](/en-US/docs/Web/SVG/SVG_as_an_Image): external resources aren't loaded, {{cssxref(":visited")}} styles [aren't applied](/en-US/docs/Web/CSS/Privacy_and_the_:visited_selector), and they cannot be interactive. To include dynamic SVG elements, try {{SVGElement("use")}} with an external URL. To include SVG files and run scripts inside them, try {{HTMLElement("object")}} inside of {{SVGElement("foreignObject")}}.
> [!NOTE]
> The HTML spec defines `<image>` as a synonym for {{HTMLElement("img")}} while parsing HTML. This specific element and its behavior only apply inside SVG documents or inline SVGs.
## Usage context
{{svginfo}}
## Attributes
- {{SVGAttr("x")}}: Positions the image horizontally from the origin.
- {{SVGAttr("y")}}: Positions the image vertically from the origin.
- {{SVGAttr("width")}}: The width the image renders at. Unlike HTML's `<img>`, this attribute is required.
- {{SVGAttr("height")}}: The height the image renders at. Unlike HTML's `<img>`, this attribute is required.
- {{SVGAttr("href")}} and {{SVGAttr("xlink:href")}}{{deprecated_inline}}: Points at a URL for the image file.
- {{SVGAttr("preserveAspectRatio")}}: Controls how the image is scaled.
- {{SVGAttr("crossorigin")}}: Defines the value of the credentials flag for CORS requests.
- {{SVGAttr("decoding")}}: Provides a hint to the browser as to whether it should perform image decoding synchronously or asynchronously.
## DOM Interface
`<image>` implements the {{domxref("SVGImageElement")}} interface.
## Example
Basic rendering of a PNG image in SVG:
### SVG
```html
<svg width="200" height="200" xmlns="http://www.w3.org/2000/svg">
<image href="mdn_logo_only_color.png" height="200" width="200" />
</svg>
```
### Result
{{EmbedLiveSample("Example", 250, 260)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}