SVG Image Element: How to Add Pictures Inside an SVG
Use the SVG image element to place PNG, JPG or SVG pictures inside a graphic. Covers href, sizing, cropping, shaped clips, embedding and missing images.
MintConvert Team
"Shapes and text aren't the only things an SVG can hold. With the <image> element, you can place a photo inside a badge, put a screenshot under labels or crop a portrait into a circle.
This isn't the same as tracing. The picture stays a picture: a PNG or JPG is still made of pixels. Tracing turns pixels into vector shapes.
Basic syntax
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 400 300">
<image href="photo.jpg" x="0" y="0" width="400" height="300" />
</svg>| Attribute | Purpose |
|---|---|
href | Address of the picture, or a data URL |
x, y | Position of the top-left corner |
width, height | Size of the rectangle for the picture. Set both for predictable results |
preserveAspectRatio | How the picture fits that rectangle |
According to MDN's element reference, SVG software must support JPEG, PNG and SVG. Older files may use xlink:href, which is deprecated in favor of href. Some older software may still expect it.
Inside HTML, use <image> only within an <svg>. For an ordinary picture on a page, use <img>.
Fit or crop the picture
| Value | Result |
|---|---|
xMidYMid meet | Shows the whole picture, centered. This is the usual default |
xMidYMid slice | Fills the rectangle and crops the overflow |
none | Stretches the picture to fill the rectangle |
These examples describe PNG and JPG pictures. A referenced SVG has some different sizing rules, so test it separately.
Crop a picture into a circle
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200">
<defs>
<clipPath id="avatar">
<circle cx="100" cy="100" r="90" />
</clipPath>
</defs>
<image href="portrait.jpg" width="200" height="200"
preserveAspectRatio="xMidYMid slice" clip-path="url(#avatar)" />
</svg>Not every application supports clipping paths. Cutting software is one place to check, as explained in our Cricut file guide.
Linked or embedded?
A linked picture stays in a separate file. An embedded picture is written into the markup as a data URL:
<image href="data:image/png;base64,PASTE_BASE64_HERE" width="400" height="300" />Replace the placeholder with your picture's Base64 data, and match the media type to its format.
| Linked | Embedded | |
|---|---|---|
| Travels as one file | No | Yes |
| SVG file size | Smaller | Larger |
| Replacing the picture | Easy | Requires editing the markup |
| Works when the SVG is used as an image | External picture isn't loaded | Data URL can be used |
That last row catches many people. A linked picture may appear in inline SVG, then vanish when the same graphic is loaded through <img> or as a CSS background. Browsers restrict external resources in that mode.
Why is my picture missing?
- Wrong path: relative addresses are resolved from a base location, so check where the file and picture are.
- No size: add
widthandheight. - External link in image mode: embed the picture.
- Outside the `viewBox`: check
x,yand the dimensions. - Covered: elements written later are painted on top. See how SVG markup is structured.
Check and export your file
Open the graphic in an SVG viewer, which can point out external links. To get a flat image from your markup, embed the pictures first, then use the code to image tool. If the file feels heavy, resize the source picture before embedding it. An SVG compressor can trim markup, but don't expect it to do the work of resizing a large embedded photo.
Key takeaways
Set href, width and height, then choose meet, slice or none. Embed pictures when your graphic must travel as one file or be displayed as an image.
Frequently asked questions
More articles
SVG Documents Explained: Structure, Elements and Examples
How SVG documents are structured: the root element, namespace, viewBox, groups, definitions, reuse, drawing order and the errors that stop a file rendering.
SVG Files for Cricut: Free Downloads, Licenses and Uploading
Using SVG files for Cricut? Learn where to get free downloads, how to check the license, how to upload to Design Space and how to fix files that look wrong.
How to Use an SVG Shape as a Background Image in CSS
Use an SVG shape as a background image in CSS. Covers sizing, stretching, placement, data URIs, changing color with masks and fixes for common problems.