The short answer
- SVG is an XML-based image and design format that represents scalable two-dimensional shapes, text, and embedded raster images, with scripts and external references possible in some processing contexts.
- In a browser, open a trusted .svg file directly or place it in an HTML image context; the latter is expected to use secure image processing. On Windows or Mac, choose a browser as the opening application. On a phone, use a browser or another viewer that documents SVG support. Decompress .svgz first if the selected application does not accept compressed SVG. Capabilities vary by context: scripts, external references, animation, and interaction may not run.
- Treat an SVG from an unknown source as active-capable content. SVG can contain scripts, event attributes such as onclick, arbitrary URI references, and external media; malicious XML entity expansion can also consume memory. Prefer a restricted or secure image-processing context that disables scripts, external references, and interaction. Successful display does not establish that the content or referenced resources are trustworthy.
SVG and SVGZ files: identify, open safely, and convert
Scalable Vector Graphics (SVG) describes two-dimensional graphics in XML. It supports vector shapes, text, embedded raster images, grouping, styles, transformations, and compositing. SVG may stand alone, appear in HTML, or be embedded in another XML language. SVGZ contains SVG wrapped in gzip compression.
Convert SVG to PNG or JPEG when a raster image is required, but keep the original SVG if scalability or editing matters. Rasterization does not preserve XML vector objects, resolution-independent editability, DOM interaction, scripts, or SVG animation. Decompressing SVGZ to SVG can preserve the underlying document without graphical loss because SVGZ is gzip-compressed SVG.
How to open it
In a browser, open a trusted .svg file directly or place it in an HTML image context; the latter is expected to use secure image processing. On Windows or Mac, choose a browser as the opening application. On a phone, use a browser or another viewer that documents SVG support. Decompress .svgz first if the selected application does not accept compressed SVG. Capabilities vary by context: scripts, external references, animation, and interaction may not run.
In a browser, open a trusted .svg file directly or place it in an HTML image context; the latter is expected to use secure image processing. On Windows or Mac, choose a browser as the opening application. On a phone, use a browser or another viewer that documents SVG support. Decompress .svgz first if the selected application does not accept compressed SVG. Capabilities vary by context: scripts, external references, animation, and interaction may not run.
Convert SVG to PNG or JPEG when a raster image is required, but keep the original SVG if scalability or editing matters. Rasterization does not preserve XML vector objects, resolution-independent editability, DOM interaction, scripts, or SVG animation. Decompressing SVGZ to SVG can preserve the underlying document without graphical loss because SVGZ is gzip-compressed SVG.
File safety
Treat an SVG from an unknown source as active-capable content. SVG can contain scripts, event attributes such as onclick, arbitrary URI references, and external media; malicious XML entity expansion can also consume memory. Prefer a restricted or secure image-processing context that disables scripts, external references, and interaction. Successful display does not establish that the content or referenced resources are trustworthy.
An unknown sender, a name ending in two extensions, or contents that do not match the extension — check before you open it.
Converting it
Convert SVG to PNG or JPEG when a raster image is required, but keep the original SVG if scalability or editing matters. Rasterization does not preserve XML vector objects, resolution-independent editability, DOM interaction, scripts, or SVG animation. Decompressing SVGZ to SVG can preserve the underlying document without graphical loss because SVGZ is gzip-compressed SVG.
Convert a copy, never the original, then compare quality, metadata, and layout against what you started with.
Common questions
What is an SVG file and what is it used for?
An SVG file is an XML document for two-dimensional graphics. It can describe scalable vector shapes, text, embedded raster images, grouping, styles, transformations, and compositing, and it may be used alone or within HTML or other XML.
How do I open an SVG file in a browser?
Open a trusted .svg file with a browser. A standalone or dynamic-interactive context may allow scripts, external references, animation, and interaction, while using SVG as an HTML image is expected to apply secure image processing. Use the restricted context for untrusted files.
How do I open an SVG file on Windows?
Choose a web browser as the application for the .svg file. If the file is .svgz and the browser does not accept it, decompress the gzip wrapper to obtain the underlying SVG first.
How do I open an SVG file on a Mac?
Open the .svg file with a browser that supports SVG. For an unfamiliar file, prefer an image-processing context that disables scripts, external references, and interaction; decompress .svgz first if necessary.
How do I open an SVG file on a phone?
Use a mobile browser or viewer that documents SVG support. Processing features vary, and .svgz may need to be decompressed before viewing. Treat files from unknown sources as active-capable content.
Why will my SVG file not open or display correctly?
The application may lack SVG support, the file may be gzip-compressed SVGZ, or the chosen processing context may disable scripts, external references, interaction, or some animation. Confirm the extension and try decompressing .svgz before choosing another documented SVG viewer.
What is the difference between SVG and SVGZ files?
SVG is the XML graphics document; SVGZ is the same kind of SVG content wrapped in gzip compression. Decompressing SVGZ can recover the underlying SVG without graphical loss, so choose SVG for direct compatibility and SVGZ when gzip wrapping is accepted.
What is lost when I convert SVG to PNG or JPEG?
Rasterization preserves a rendered image, not the original SVG feature model. The result loses XML vector objects, resolution-independent editability, DOM interaction, scripts, and declarative SVG animation. Retain the SVG when those capabilities matter.
Can SVG files contain scripts, and are unknown SVG files safe to open?
SVG can contain script elements, event attributes, external references, and arbitrary URIs. XML entity expansion or referenced media can add further risk. Do not assume an unknown SVG is safe; open or convert it in a restricted context that disables active and external content.
What is the SVG MIME type, and does SVG have a magic number?
The registered media type is image/svg+xml. The W3C registration identifies .svg and the gzip-compressed .svgz alias, but supplies no format-specific magic number, so no reliable binary signature is asserted.
Related formats
Sources
Scalable Vector Graphics (SVG) 2 · World Wide Web Consortium (W3C)
Introduction — SVG 2 · World Wide Web Consortium (W3C)
Media Type Registration for image/svg+xml — SVG 2 · World Wide Web Consortium (W3C)
IANA Media Types Registry · Internet Assigned Numbers Authority (IANA)
Scripting and Interactivity — SVG 2 · World Wide Web Consortium (W3C)