All formats

SVG (Scalable Vector Graphics)

Full nameScalable Vector Graphics
Extensions.svg, .svgz (gzip-compressed SVG)
MIME typeimage/svg+xml (also for .svgz, served with Content-Encoding: gzip)
Typevector image, XML text
Starts withno fixed signature: XML text, usually <?xml or <svg (may follow a UTF-8 BOM, comments or a <!DOCTYPE>); .svgz starts with 1F 8B (gzip)
SpecificationSVG 2 (W3C Candidate Recommendation), SVG 1.1 Second Edition (W3C Recommendation)
Maintained byW3C (SVG Working Group)
Licenseopen, royalty-free

SVG describes images as shapes, paths, text and gradients in XML instead of as a grid of pixels. An SVG image scales to any size without losing sharpness, and its file size depends on the complexity of the drawing, not on its pixel dimensions. It’s the standard format for icons, logos, charts, maps, diagrams and illustrations on the web, and every web browser renders it natively.

Because SVG is XML text, you can write it by hand, generate it from code, style it with CSS, change it with JavaScript in a web page, compress it well with gzip or Brotli, and keep it in version control. Desktop apps (Inkscape, Illustrator, Figma, Affinity) use it as an exchange format for vector artwork.

When to use SVG#

File structure#

An SVG file is an XML document with an <svg> root element in the http://www.w3.org/2000/svg namespace. A complete, minimal file:

XML
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" width="200" height="100" viewBox="0 0 200 100">
  <title>Example</title>
  <defs>
    <linearGradient id="sky" x1="0" y1="0" x2="0" y2="1">
      <stop offset="0" stop-color="#4a90e2"/>
      <stop offset="1" stop-color="#ffffff"/>
    </linearGradient>
  </defs>
  <rect width="200" height="100" fill="url(#sky)"/>
  <circle cx="150" cy="40" r="25" fill="orange"/>
  <path d="M0 100 L60 50 L110 90 L150 60 L200 100 Z" fill="#2e8b57"/>
  <text x="10" y="25" font-family="sans-serif" font-size="16">Hello, SVG</text>
</svg>

Size and viewBox#

Elements#

Group Elements Purpose
Shapes rect, circle, ellipse, line, polyline, polygon, path geometry; path can draw anything
Text text, tspan, textPath text with system or web fonts (or @font-face)
Structure g, defs, use, symbol, svg, switch grouping, reusable definitions, nested viewports
Paint linearGradient, radialGradient, pattern fills and strokes referenced by url(#id)
Clipping clipPath, mask hide parts of other elements
Effects filter with feGaussianBlur, feOffset, feColorMatrix, … blur, shadows, color changes (pixel operations)
Other content image, foreignObject, marker embedded raster images, HTML, arrowheads
Metadata title, desc, metadata accessible name, description, RDF metadata
Dynamic style, script, a, animate, animateTransform, set CSS, JavaScript, links, SMIL animation

Styling uses presentation attributes (fill="red"), the style attribute (style="fill:red") or CSS in a <style> element. CSS overrides presentation attributes. transform="translate(10 20) rotate(45) scale(2)" applies to any element or group.

Path data#

The d attribute of <path> is a compact list of commands. Uppercase commands use absolute coordinates, lowercase are relative to the current point.

Command Parameters Meaning
M / m x y move to (start a new subpath)
L / l x y line to
H / h, V / v x, y horizontal / vertical line
C / c x1 y1 x2 y2 x y cubic Bézier curve
S / s x2 y2 x y smooth cubic Bézier (first control point mirrored)
Q / q x1 y1 x y quadratic Bézier curve
T / t x y smooth quadratic Bézier
A / a rx ry rotation large-arc sweep x y elliptical arc
Z / z close the subpath

Example: M10 10 h80 v80 h-80 Z draws a 80 x 80 square. Commas and spaces are interchangeable, and a repeated command letter can be omitted.

SVGZ#

An .svgz file is an SVG file compressed with gzip, so it starts with the gzip signature 1F 8B 08. SVG text compresses well (often 50-80% smaller). Web servers usually compress .svg on the fly instead; if you serve .svgz files, send Content-Type: image/svg+xml and Content-Encoding: gzip, or browsers show garbage.

Profiles and versions#

Version Status Notes
SVG 1.1 Second Edition W3C Recommendation the baseline almost every renderer supports
SVG 2 W3C Candidate Recommendation adds paint-order, href without xlink:, CSS integration, vector-effect; browsers implement most of it
SVG Tiny 1.2 W3C Recommendation subset for mobile devices; the base of the SVG profile used for brand logos in email (BIMI)

Write href="..." for SVG 2 renderers and xlink:href="..." (with xmlns:xlink="http://www.w3.org/1999/xlink") when older renderers must read the file.

Making SVG files smaller#

Converting SVG#

Rasterize SVG to PNG or convert it to PDF from the command line:

Shell
# librsvg
rsvg-convert -w 512 in.svg -o out.png
rsvg-convert -f pdf -o out.pdf in.svg
# resvg
resvg -w 512 in.svg out.png
# Inkscape 1.x
inkscape in.svg --export-type=png --export-width=512 --export-filename=out.png
inkscape in.svg --export-type=pdf --export-filename=out.pdf
# ImageMagick (uses its own renderer or librsvg)
magick -density 192 -background none in.svg out.png

Renderers differ in how much of SVG they support, especially text, filters and CSS. The resvg test suite support table compares browsers and libraries.

Security#

SVG is a document format, not just a picture, and needs care when it comes from untrusted users:

Specifications and documentation#

Software that opens SVG files#

SoftwareWindowsmacOSLinuxWebCanNotes
SumatraPDF✓viewfree, open source; opens .svg files as images
Web browsers✓✓✓✓viewChrome, Edge, Firefox, Safari: the most complete SVG renderers, with CSS, scripts and animation. Also on Android and iOS
Inkscape✓✓✓view, edit, create, convertfree, open source vector editor; SVG is its native format
Adobe Illustrator✓✓view, edit, create, convertcommercial
Affinity✓✓view, edit, create, convertfree vector and photo editor from Canva
Figma✓✓✓edit, create, convertimports and exports SVG; free tier
Boxy SVG✓✓✓✓view, edit, createSVG editor, commercial
SVG-Edit✓view, edit, createfree, open source, runs in the browser
LibreOffice Draw✓✓✓view, edit, convertfree, open source; imports and exports SVG
GIMP✓✓✓view, convertfree, open source; rasterizes SVG on import, imports paths
Krita✓✓✓view, editfree, open source; imports SVG as a vector layer
Photopea✓view, edit, convertfree, runs in the browser
ImageMagick✓✓✓convertcommand line, open source
rsvg-convert✓✓✓convertcommand line from librsvg: SVG to PNG, PDF, PS
SVGO✓✓✓convertcommand line SVG optimizer (Node.js)
SVGOMG✓convertSVGO in the browser

Libraries#

Open-source libraries that render, parse and generate SVG. See all SVG libraries for a comparison.

C/C++librsvg, LunaSVG, NanoSVG
C#SVG.NET, Svg.Skia
JavaBatik, JFreeSVG, JSVG
Gocanvas, oksvg, SVGo
PythonCairoSVG, drawsvg, svglib
Rubyruby-vips, Victor
Rustresvg, svg
PHPImagick, php-svg