Remove SVG Metadata Without Breaking the Drawing
An SVG that comes out of Inkscape, Illustrator or Figma carries a second file inside it: the editor's document state. On a 36-path Inkscape export of 26,554 bytes it accounted for 5,562 bytes across metadata blocks, namespace declarations, editor attributes, unreferenced ids and pretty-printing. Removing all of it, in nine steps, changed zero pixels of the render. 26,554 bytes became 21,544, a 18.8% cut, with no visible difference; rounding the path data from six decimals to two took it to 17,232 bytes for a worst-case shift of 0.05 px. The three deletions that do break a file are all in the same family: a namespace declaration, a referenced id, and whitespace a text element was relying on.
The file used here is a real one from this site's own optimiser test folder,
car-lite.svg: Inkscape 0.47, 36 paths, 9 gradients, 80 ids of which 11 are referenced, a Creative
Commons public-domain licence in its RDF block. Every byte count below comes from removing one thing and
re-measuring the file; every pixel count comes from re-rendering it at 480 px and diffing against the previous
step.

Six kinds of thing that call themselves metadata
They are not one category, and they do not cost the same. Measured in the order a cleanup would remove them, so that the parts add up to the file exactly once:
| What it is | Bytes | Share | Written by |
|---|---|---|---|
Path data, 36 d attributes | 12,167 | 45.8% | the drawing itself |
Gradients, filters and everything else in <defs> | 8,819 | 33.2% | the drawing |
XML declaration, comments, inkscape:perspective, sodipodi:namedview, RDF <metadata> | 2,429 | 9.2% | Inkscape |
Editor attributes left after those blocks are gone (inkscape:label, sodipodi:docname, ...) | 622 | 2.3% | Inkscape |
Namespace declarations nothing uses any more (xmlns:dc, xmlns:rdf, xmlns:inkscape, ...) | 330 | 1.2% | Inkscape |
Ids no url(#) or href="# points at | 1,623 | 6.1% | Inkscape numbering every node |
| Indentation: one attribute per line | 558 | 2.1% | the XML serialiser |
Measured in isolation the numbers are larger — editor attributes alone are 1,426 bytes, ids alone are
2,050, indentation alone is 814 — because removing the namedview block also removes the
inkscape:* attributes it contains. Any article quoting one number per category without saying
whether it is isolated or cumulative is quoting two different sums.
What the nine steps bought
| Step | File size | Saved | Pixels changed |
|---|---|---|---|
| S0 as delivered (namespaces fixed) | 26,548 B | — | 0 px |
| S1 xml declaration | 26,494 B | −54 | 0 px |
| S2 comments | 26,436 B | −58 | 0 px |
| S3 inkscape:perspective | 25,907 B | −529 | 0 px |
| S4 sodipodi:namedview | 25,392 B | −515 | 0 px |
| S5 | 24,119 B | −1,273 | 0 px |
| S6 editor attributes | 23,497 B | −622 | 0 px |
| S7 unused namespace declarations | 23,167 B | −330 | 0 px |
| S8 unused ids | 21,544 B | −1,623 | 0 px |
| S9 indentation | 20,986 B | −558 | 0 px |
Every step is free in pixels, including the one that deletes 68 ids. That last one deserves a note, because
it is the step people are afraid of: of the 80 ids in the file, 11 are referenced, one more (base)
belonged to the namedview block that was already gone, and the remaining 68 point at nothing. The
stripper checks the references before it touches anything, so the ids that survive are the ones a gradient or a
filter is pointing at.
Delete attributes before namespace declarations
Order matters, and the failure is loud. If you remove xmlns:inkscape while
inkscape:version is still on the root element, the file stops being XML. Parsing the result gives
Attribute inkscape:version prefix is unbound, and the image never loads: the natural size is 0 and
the browser reports an encoding error rather than a drawing. Remove the attributes first, then the declaration
only if no element or attribute still uses the prefix.
The same trap exists for sodipodi, dc, cc and rdf. The
stripper below re-checks each declaration against the remaining text instead of removing a fixed list, because
the fixed list is correct only for the file you tested it on.
Three deletions that do move pixels
Referenced ids. Deleting the id attributes of the gradients took the render from
37,095 units of ink to 28,440 and changed 18,721 pixels, with a channel difference
of 255 at the worst pixel. A gradient with no id is a gradient nothing can
reference; it disappears and the fill falls back to black or to nothing.
xml:space="preserve". On a label written as A B C,
keeping the attribute measured 80.7 px of text; removing it collapsed the runs of spaces and left 56.3 px, a
30.2% narrower label, with 484 pixels changed. SVG collapses whitespace by default and
that attribute is the only thing turning it off, so it is not editor state even though it looks like it.
<title> and <desc>. Zero pixels, by design: they are the
accessible name and the description. They are also the part of the file an AI assistant or a screen reader
reads first, so a cleanup that deletes them makes a file lighter and less useful at the same time.
The namespace line a bulk find-and-replace broke
The file used for this page arrived with every w3.org URI rewritten from http to
https, including xmlns="https://www.w3.org/2000/svg". Namespace URIs are identifiers,
not addresses: the SVG namespace is exactly http://www.w3.org/2000/svg, and with the
s in place the root element is not an SVG element at all. The file still parses as XML and still
looks correct in a text editor. In the browser it has a natural size of 0 × 0 and throws
EncodingError when decoded as an image. Restoring those six strings was a 6-byte change that made a
dead file render at 351 × 248.
It is worth checking before any other cleanup, because every other measurement is meaningless on a file that
draws nothing. Search for https://www.w3.org/ in any SVG that fails to show up; the same wrong
rewrite hits xmlns:xlink and the RDF namespaces, which is how a file ends up with a licence block no
processor can read.
Some metadata is the licence
The RDF block in this file is 1,273 bytes and contains the title, the creator (Onsemeliot), the date, three subject tags and a Creative Commons public-domain dedication. It is metadata, it is not editor state, and on a file you did not draw it may be the attribution the licence requires. Strip the parts that describe the editing session — zoom level, window position, the current layer, the perspective helper — and keep the parts that describe authorship, unless you own the file and have decided otherwise.
The same rule applies to Adobe exports, where <metadata> often carries an XMP packet with a
base64 thumbnail of the artwork. That thumbnail is real weight — base64 turns three bytes into four, so a
6 KB preview costs 8 KB in the file — but it sits in the same element as the copyright notice. Read the
element before deleting it.
Reduce precision only after the cleanup
| Path data | File | Saved | Worst deviation | Pixels changed |
|---|---|---|---|---|
| 4 decimals | 19,735 B | −6.0% | 0.06 px | 82 px |
| 3 decimals | 18,486 B | −11.9% | 0.01 px | 39 px |
| 2 decimals | 17,232 B | −17.9% | 0.05 px | 312 px |
| 1 decimals | 15,847 B | −24.5% | 0.46 px | 1,013 px |
Two decimals cost 0.05 px of geometry, which is under a device pixel at the 480 px render used here; one decimal costs 0.46 px and changes 1,013 pixels of a 480×339 canvas, because a half-pixel shift on a gradient edge is visible. The precision itself is a separate subject with its own arithmetic — how many decimals a path needs — but the order is fixed: metadata first, because it is free, then precision, because it is not.
A stripper that refuses to break references
This function removes the blocks, then the attributes, then the declarations that nothing uses any more, then the ids nothing points at. Running it twice changes nothing the second time.
function stripMetadata(svg) {
var out = svg
.replace(/<\?xml[^>]*\?>/g, '')
.replace(/<!--[\s\S]*?-->/g, '')
.replace(/<metadata\b[\s\S]*?<\/metadata>/gi, '')
.replace(/<sodipodi:namedview\b[\s\S]*?\/>/g, '')
.replace(/<inkscape:perspective\b[\s\S]*?\/>/g, '')
.replace(/\s+(?:inkscape|sodipodi|i|graph|sketch|dc|cc|rdf):[\w:-]+="[^"]*"/g, '');
// namespace declarations may only go once no element or attribute uses them
out = out.replace(/\s+xmlns:([\w-]+)="[^"]*"/g, function (m, prefix) {
var used = new RegExp('[\\s<]' + prefix + ':', 'm').test(out);
return used ? m : '';
});
// ids may only go when no url(#id) or href="#id" points at them
var refs = {};
var rre = /url\(#([^)]+)\)|href="#([^"]+)"/g;
var r;
while ((r = rre.exec(out))) refs[r[1] || r[2]] = true;
out = out.replace(/\s+id="([^"]*)"/g, function (m, id) {
return refs[id] ? m : '';
});
// Inkscape and Illustrator pretty-print with one attribute per line
return out.replace(/>\s+</g, '><').trim();
}
Two checks to run on the result before you ship it: every reference still resolves, and no namespace URI was rewritten.
function auditRefs(svg) {
var ids = {};
var ire = /\sid="([^"]*)"/g;
var m;
while ((m = ire.exec(svg))) ids[m[1]] = true;
var broken = [];
var rre = /url\(#([^)]+)\)|(?:xlink:)?href="#([^"]+)"/g;
while ((m = rre.exec(svg))) {
var ref = m[1] || m[2];
if (!ids[ref] && broken.indexOf(ref) === -1) broken.push(ref);
}
if (/<use\b[^>]*href="#([^"]+)"/.test(svg)) { /* counted above */ }
return broken;
}
function namespaceWarnings(svg) {
var w = [];
if (!/xmlns="http:\/\/www\.w3\.org\/2000\/svg"/.test(svg)) {
w.push('root element is not in the SVG namespace');
}
if (/xmlns(?::\w+)?="https:\/\/(?:www\.)?w3\.org\//.test(svg)) {
w.push('a w3.org namespace URI was rewritten to https');
}
if (/[\s<](?:inkscape|sodipodi):[\w:-]+=/.test(svg) && !/xmlns:inkscape="/.test(svg)) {
w.push('prefixed attribute without its namespace declaration');
}
return w;
}
Verify in three gates
- It still parses.
new DOMParser().parseFromString(svg, 'image/svg+xml')must return noparsererror. This is the gate that catches an unbound prefix. - References resolve, and the root is in the SVG namespace.
auditRefsreturns an empty list;namespaceWarningsreturns an empty list. - The pixels are identical. Render both versions at the size you ship and diff them. Count only channel differences above 8, or antialiasing noise will look like a regression.
A file that passes all three is smaller for free. A file that passes one and not the others is the normal outcome of a find-and-replace cleanup, and it is the reason this page exists: nothing about the deleted bytes tells you whether the drawing survived.
Related SVG Workflows
Metadata is the free half of file size. These pages cover the half that costs pixels.
- SVG Decimal Precision — how many decimals the path data needs, measured across four render scales.
- Why Is My SVG File So Large? — the same file weighed against nine others that draw the same scene.
- Figma SVG Clean Code — what Figma leaves behind, and which of it is safe to delete.
- Best Free SVG Optimizer Tools — what each one removes by default, including the licence block.
- SVG Namespace Security — why the namespace a file declares decides whether it renders or executes.
- SVG File Too Large: How to Reduce It — the reduction ladder from export settings to rewrites.
- SVG Validator — check structure and references before and after a cleanup.
Try These Free Online Tools
No download required — convert, compress & optimize SVGs right in your browser



