Skip to content

image/svg+xml MIME Type — Meaning, Usage & Examples

image/svg+xml
Extensions: .svg Class: image Spec: W3C (IANA registered)
View IANA registration ↗

image/svg+xml means: image/svg+xml is the media type for Scalable Vector Graphics, an XML-based format describing images with shapes, paths and text rather than pixels. SVG scales to any resolution without quality loss, making it ideal for icons, logos and responsive illustrations. Image media types identify raster and vector graphics. The subtype selects the decoder and influences compression, transparency and animation support. Serving the right image type lets browsers pick efficient decoding paths, enables responsive srcset negotiation, and avoids the broken-image icon that appears when bytes and declared type disagree. You will encounter image/svg+xml in contexts such as resolution-independent icons and logos; inline vector illustrations and charts in html; responsive graphics that must stay crisp on any display. It is commonly associated with the file extension(s) .svg. SVG is XML and can contain scripts, so untrusted SVG is an XSS vector when rendered inline or as an image in some contexts. Sanitize SVG uploads, strip script elements and event handlers, and serve user SVG with a restrictive Content-Security-Policy.

Advertisement
Ad slot · ref-top

When you'll see image/svg+xml

  • Resolution-independent icons and logos
  • Inline vector illustrations and charts in HTML
  • Responsive graphics that must stay crisp on any display

How to handle it

When serving images, match the Content-Type to the actual encoded bytes, set long-lived cache headers for immutable assets, and provide width/height or aspect-ratio hints to avoid layout shift. Use responsive delivery (srcset, picture, or server content-negotiation) so clients receive a format they support at an appropriate resolution. Validate uploaded images by decoding them, not by trusting the extension or the client-supplied type. As a final checklist for image types: compress and resize for the display slot, serve modern formats with fallbacks, add width and height to prevent layout shift, cache immutable assets aggressively, and validate uploads by decoding rather than trusting the claimed type or extension.

Notes & gotchas

SVG is XML and can contain scripts, so untrusted SVG is an XSS vector when rendered inline or as an image in some contexts. Sanitize SVG uploads, strip script elements and event handlers, and serve user SVG with a restrictive Content-Security-Policy.

Examples

HTTP
HTTP/1.1 200 OK
Content-Type: image/svg+xml
Content-Disposition: inline; filename="sample.svg"

[binary image payload: the encoded bytes of a sample .svg]
curl
curl -i -H "Accept: image/svg+xml" https://api.example.com/v1/resource   # inspect the returned Content-Type
JavaScript (fetch)
const res = await fetch("/media/sample.svg", { headers: { Accept: "image/svg+xml" } });
const blob = await res.blob();            // blob.type should be "image/svg+xml"
const url = URL.createObjectURL(blob);    // assign to img.src / audio.src / video.src
// revoke with URL.revokeObjectURL(url) when done to free memory
Python (requests)
import requests

res = requests.get("https://api.example.com/v1/resource",
                   headers={"Accept": "image/svg+xml"}, timeout=30)
res.raise_for_status()
assert res.headers["Content-Type"].startswith("image/svg+xml")
with open("sample.svg", "wb") as fh:
    fh.write(res.content)   # raw bytes; use stream=True for large files

Frequently asked questions

Is SVG safe to accept from users?

Not without sanitization — SVG can embed JavaScript and external references. Strip scripts and event attributes, or rasterize untrusted SVG, and never serve it inline from your main origin without a CSP.

Why use image/svg+xml instead of image/svg?

The +xml suffix follows the XML media-type convention and is the registered form. It tells parsers the content is XML-based vector graphics.

How do browsers choose between image formats?

Through the Accept header and srcset/sizes or the picture element. The server can content-negotiate (e.g. serve WebP/AVIF to clients that accept it), and the declared Content-Type must match the bytes actually sent.

Does the file extension determine the MIME type?

No — the server declares Content-Type, and the bytes must match it. Extensions are a convenience for mapping, but a .png file served as image/jpeg, or vice versa, can render incorrectly or be rejected by strict clients.

How do I prevent layout shift when images load?

Set explicit width and height attributes (or CSS aspect-ratio) so the browser reserves space before the image arrives, and use responsive srcset/sizes to deliver an appropriately sized file for each viewport.

Advertisement
Ad slot · ref-in-article

Try the HTML Entity Encoder

Escape and unescape HTML entities safely.

Open tool →