XML ValidatorDeveloper Tools
Checks XML for well-formedness and explains each syntax error.
Check an SVG file for errors before you ship it. The SVG validator finds broken XML, a missing namespace or viewBox, broken references, duplicate ids, typos in attributes, and unsafe scripts.
Checks as you type for files up to 200 KB.
First the file is parsed as strict XML 1.0. A broken file stops there with the line and column of the error. A well-formed file then goes through these checks:
<svg> and carries xmlns="http://www.w3.org/2000/svg".viewBox is present and has four numbers with a positive width and height; width and height are valid lengths.url(#id), href="#id", and xlink:href="#id" points to an element that exists, and no id is used twice.inkscape: attributes is listed as a note.<script>, on... event handlers, javascript: links, and files loaded from other addresses are flagged.The sample file has five typical problems:
fill="url(#fade2)" points to an id that does not exist (the gradient is called fade).id="card".strok-width is a typo for stroke-width, so browsers ignore it.onclick is an event handler.viewBox, so the file won't scale in CSS.| Level | Meaning | Examples |
|---|---|---|
| Error | The file is broken or part of it can't work | Unclosed tag, missing namespace, broken reference, duplicate id |
| Warning | It works, but something is probably wrong or risky | No viewBox, unknown attribute, script, external file |
| Note | Harmless, worth knowing | Editor metadata, foreignObject |
<style> is not validated, except for references and imports.Broken XML (an unclosed tag, an unescaped &), a root element that is not svg, a missing SVG namespace, a malformed viewBox, references to ids that don't exist, or the same id used twice.
Browsers forgive a lot when SVG is inside HTML. The same file used as an image, in an email, or in a design app often fails. The validator checks the file as a standalone SVG.
Yes. The file is only read as text and never drawn or run, so scripts in it can't do anything. They are listed as warnings.
No, it reports them with line numbers. The SVG Optimizer can clean up many warnings, and the SVG ViewBox Generator adds a missing viewBox.
Often used together with the SVG Validator.
Checks XML for well-formedness and explains each syntax error.
Adds a viewBox to SVG files from their width and height or their drawn content.
Indents SVG code for reading and editing without changing any values.