Introduction
SVG is the W3C’s vector image format for the web. SVG 1.0 became a Recommendation in 2001 and SVG 1.1 in 2003, with a second edition in 2011; SVG 2 is a Candidate Recommendation, and SVG Tiny 1.2 (2008) is a smaller profile for mobile devices. An SVG file is XML text that describes shapes, paths, text, gradients, patterns, masks and filters, so it can be written by hand, styled with CSS, scripted and searched.
Every current browser draws SVG directly, and it can sit inside an HTML page as an
element. It is the usual format for logos, icons, charts and diagrams on the web. A
gzip-compressed SVG uses the extension .svgz.
Structure
An SVG file is an XML document whose root element is <svg> in the
namespace http://www.w3.org/2000/svg. The viewBox attribute
sets the coordinate system, and width and height its displayed
size. Inside it, drawing elements such as path, rect,
circle and text paint in document order, so later shapes sit on
top. Shapes can be grouped with g, defined once in defs and
reused with use.
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
<rect x="10" y="10" width="80" height="80" fill="#0f7f49"/>
<circle cx="50" cy="50" r="25" fill="white"/>
</svg>
The reference pages list every element, the attributes and properties with their values, and the path data commands.
Pages by family
Elements
- Structure, linking and embedding – svg, g, defs, symbol, use, switch, a, view, image, foreignObject
- Shapes – path, rect, circle, ellipse, line, polyline, polygon
- Text – text, tspan, textPath and the SVG 1.1 tref and altGlyph family
- Gradients and patterns – linearGradient, radialGradient, stop, pattern
- Clipping, masking and markers – clipPath, mask, marker
- Filters – filter and every filter primitive
- Animation – animate, set, animateMotion, mpath, animateTransform, discard
- Metadata, scripts and styles – title, desc, metadata, script, style
- Legacy, Tiny and draft – SVG fonts, cursor, color-profile, SVG Tiny 1.2 and draft SVG 2 elements
Attributes and properties
- Core, conditional and event attributes – id, class, style, lang, aria-*, systemLanguage, onclick
- Presentation properties – fill, stroke, opacity, display, overflow, blending
- Geometry – lengths, x, y, width, height, cx, cy, r, points, d
- Coordinate systems – viewBox, preserveAspectRatio, transform, units
- Text – font and text properties
- References – href, xlink:href, url(#id)
- Gradients, patterns, markers, clip paths and masks – their attributes
- Filter effects – every primitive attribute
- Animation – SMIL values and timing
The file
In the explorer
Drop a .svg or .svgz file on the explorer. It shows:
- Picture: the drawing, handed to the browser as an image, so scripts and outside files never load. The SVG is not put into the page.
- Text: the source, coloured, with numbers, colours, CSS and script inside it marked.
- Overview: size, view box, title, description, tool that made it, elements by family, other vocabularies, and every problem found.
- Features: what the file uses (filters, scripts, SMIL, foreignObject, SVG 1.1 features SVG 2 removed) and which readers may not draw it.
- Resources: ids, references and whether each leads to the right kind of element, colour swatches and a colour table, fonts, external addresses and embedded images (each can be opened as a file).
- Code: scripts, style sheets and rules, and animations.
- Paths: every path with its commands, subpaths and box, a table of the commands used, and the filter chains.
- Structure tree: every element and attribute with a note on what it is and a link to its reference page; path data, point lists, transforms, style attributes and view boxes open into their parts, each tied to its bytes.
A .svgz opens as a gzip file; its payload opens as an SVG.
Not described
This reference and the explorer’s viewer are partial. The detail for each page is in the “Not described” section at the end of that page.
Known, not yet covered
- Reference: every default and rule here was written from knowledge of the published specifications, not checked line by line against SVG 1.1 Second Edition, SVG 2 (W3C Candidate Recommendation), CSS Masking, Filter Effects, CSS Transforms and CSS Fonts.
- Reference: SVG Tiny 1.2 (W3C Recommendation, 2008) is covered only by the names of its extra elements, on the legacy elements page.
- Reference: the content model (allowed children) of each element, defined in the SVG 1.1 and SVG 2 element definitions, is described only in part.
- Reference: the SMIL timing model (SMIL Animation), text layout (SVG 2 and CSS Text), the filter algorithms (Filter Effects) and CSS transform syntax are summarised, not written out; see animation, text and filters.
- Reference: CSS properties browsers accept on SVG elements beyond those listed on the presentation page.
- Viewer: does not draw SVG itself. The Picture is the browser’s rendering as an image and is not linked to elements. Libraries such as resvg and librsvg render SVG outside a browser.
- Viewer: a file over 48 MiB (or a decoded entry over 8 MiB) is read in windows. It has the Picture
(the browser’s own decoding, up to 128 MiB; a bigger file says it is too large to draw and gives the size from the
root element), Features, Resources, Code and Paths tabs, made by one walk over the elements that holds only the open
ones, with every table in pages. Lists stop at 200,000 entries of a kind (ids at 1,000,000) and the rest are counted.
Not done in windows: a
useinside the element it draws, the stops of a gradient and the children of a pattern, comments and processing instructions (so the generator comment andxml-stylesheetare not read), and style or script text beyond 100,000 characters in one run. - Viewer: does not match CSS selectors or work out the cascade (CSS Selectors); it lists rules, colours, fonts and addresses instead.
- Viewer: does not parse animation
begin,endor clock values, and does not checkkeyTimes,keySplines,kernelMatrixsizes or light-source values (SMIL Animation, Filter Effects); it lists the animations and checks the ids they name. - Viewer: does not resolve
hrefchains of gradients, patterns and filters, percentages,emunits or the combined transform of an element; values are shown as written. - Viewer: recognises SVG 1.1 font elements, SVG Tiny 1.2 elements and draft SVG 2 elements but does not check their attributes or turn SVG fonts into glyphs.
- Viewer: checks only a few parent rules (stop, feFunc*, feMergeNode, mpath, light sources, tspan, textPath, filter primitives), not every content model.
- Viewer: does not fetch outside addresses or follow
useandimageinto other files; it lists them. - Viewer: arc bounding boxes are sampled, not exact, and path length is not measured. In a file held whole, tables stop at 3,000 rows; a file over 48 MiB is read in windows (see above) and has no size limit, and the Text tab is shown in windows of 1 MiB so every byte is reachable.
Unknown
- Reference and viewer: the private data that editors keep in their own namespaces (for example Adobe Illustrator’s) has no public specification, so it is shown by name only, as another vocabulary. Inkscape’s data is open source and could be covered.
Links
Software
- Inkscape – free vector editor whose native format is SVG (Windows, macOS, Linux)
- Adobe Illustrator – Adobe’s vector editor, which opens and exports SVG (Windows, macOS)
- Figma – interface design tool that imports and exports SVG (web browser, Windows, macOS)
- Boxy SVG – vector editor that works directly on SVG files (web browser, Windows, macOS, Linux)
- CorelDRAW – Corel’s vector editor, which imports and exports SVG (Windows, macOS)
- SVGO – command-line tool that makes SVG files smaller (Windows, macOS, Linux)
- ImageMagick – command-line tool that converts SVG to raster images (Windows, macOS, Linux)
- Firefox – web browser that displays SVG, as do Chrome, Safari and every current browser (Windows, macOS, Linux, mobile)
Developers
Reference
- Scalable Vector Graphics (SVG) 1.1 – the W3C Recommendation
- Scalable Vector Graphics (SVG) 2 – the W3C’s newer specification