
Validate SVG
Check an SVG for well-formed XML, a proper svg root, unclosed tags and non-SVG elements, and flag any href pointing outside the file, entirely with a hand-rolled scanner.
Validate SVG runs a hand-rolled scanner, not a general XML parser. It reports whether the file is well formed, names its root element and element count, and flags any tag outside the set SVG 1.1 and SVG2 define. An href pointing outside the file is flagged too. Nothing is fixed or rewritten; the file only gets read and reported on.
Questions
Is this a real XML parser?
No. It is a hand-rolled scanner built to answer specific questions about an SVG document, matching open tags against their closes in order and collecting issues along the way; it is not a general-purpose XML parser and does not try to be one.
What counts as an unknown element?
Any local element name, ignoring a namespace prefix, that is not in the fixed list of elements SVG 1.1 and SVG2 define. That usually means HTML markup that ended up inside an SVG document by mistake, though it can also be a real but obscure SVG element the list happens to miss.
Which hrefs get flagged as external?
Any href or xlink:href whose value starts with an absolute URL scheme, such as http:// or https://, or any other scheme prefix that is not a bare # fragment or a data: URI.
Does it fix anything it finds?
No. It only reads the file and reports what it found; nothing about the SVG is rewritten or corrected.
What kinds of issues does it report on a badly formed file?
Things like an element that is never closed, a closing tag that does not match the open tag it pairs with, content appearing after the root element has already closed, and a root element that is not svg at all, each one reported at its byte offset in the file.
Compare
| Tool | Runs on the CLI | Live as you type |
|---|---|---|
| Validate SVG | Yes | Yes |
| Set SVG viewBox | Yes | Yes |
| Recolor SVG | Yes | Yes |
| Convert SVG text to paths | Yes | No |
| Inspect an SVG path | Yes | Yes |