Updated November 23, 2026  ·  10 min read  ·  SVGVector

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.

A stacked bar of 26,548 bytes: 12.2 kilobytes of path data, 2.4 of metadata blocks, 0.6 of editor attributes, 1.6 of unused ids, 0.6 of indentation and 9.1 of gradients and structure. Below it three bars: 26,548, then 20,986 after cleanup with zero pixels changed, then 17,232 after rounding to two decimals.
car-lite.svg, a 36-path Inkscape 0.47 export. The pieces are measured in the order a cleanup would remove them, so they add up to the file exactly once.

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 isBytesShareWritten by
Path data, 36 d attributes12,16745.8%the drawing itself
Gradients, filters and everything else in <defs>8,81933.2%the drawing
XML declaration, comments, inkscape:perspective, sodipodi:namedview, RDF <metadata>2,4299.2%Inkscape
Editor attributes left after those blocks are gone (inkscape:label, sodipodi:docname, ...)6222.3%Inkscape
Namespace declarations nothing uses any more (xmlns:dc, xmlns:rdf, xmlns:inkscape, ...)3301.2%Inkscape
Ids no url(#) or href="# points at1,6236.1%Inkscape numbering every node
Indentation: one attribute per line5582.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

StepFile sizeSavedPixels changed
S0 as delivered (namespaces fixed)26,548 B—0 px
S1 xml declaration26,494 B−540 px
S2 comments26,436 B−580 px
S3 inkscape:perspective25,907 B−5290 px
S4 sodipodi:namedview25,392 B−5150 px
S5 RDF24,119 B−1,2730 px
S6 editor attributes23,497 B−6220 px
S7 unused namespace declarations23,167 B−3300 px
S8 unused ids21,544 B−1,6230 px
S9 indentation20,986 B−5580 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 dataFileSavedWorst deviationPixels changed
4 decimals19,735 B−6.0%0.06 px82 px
3 decimals18,486 B−11.9%0.01 px39 px
2 decimals17,232 B−17.9%0.05 px312 px
1 decimals15,847 B−24.5%0.46 px1,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

  1. It still parses. new DOMParser().parseFromString(svg, 'image/svg+xml') must return no parsererror. This is the gate that catches an unbound prefix.
  2. References resolve, and the root is in the SVG namespace. auditRefs returns an empty list; namespaceWarnings returns an empty list.
  3. 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.

Try These Free Online Tools

No download required — convert, compress & optimize SVGs right in your browser

Strip

SVG Optimiser

Remove metadata and unused defs in one pass, with a byte count.

Open optimiser
Validate

SVG Validator

Confirm the file still parses after a cleanup.

Open validator
Inspect

SVG to Code

Read the markup as text and find the editor state yourself.

Read the code
Compare

SVG to PNG

Render before and after and diff the result at ship size.

Render it
Compress

Image Compressor

Shrink the raster that is carrying the real weight.

Compress it
Edit

SVG Editor

Open the cleaned file and check the gradients still resolve.

Open editor