SVG Validator

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.

Updated
Runs in your browser. Your SVG is not uploaded.

Your SVG

Checks as you type for files up to 200 KB.

Report

Your report will appear here
  1. Paste SVG code, upload a file, or load a URL
  2. Read the problems found
  3. Fix them and check again

How to use the SVG Validator

  1. Paste the SVG code or drop the file on the text box. Files up to 200 KB are checked as you type.
  2. Read the summary: valid, valid with warnings, or not valid.
  3. Go through the list. Each problem shows its line number and what to do about it.
  4. Fix the code and watch the list shrink.

How it works

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:

  • Root: the root is <svg> and carries xmlns="http://www.w3.org/2000/svg".
  • Size: viewBox is present and has four numbers with a positive width and height; width and height are valid lengths.
  • References: every url(#id), href="#id", and xlink:href="#id" points to an element that exists, and no id is used twice.
  • Names: elements and attributes are part of SVG 1.1 or SVG 2. Editor data such as inkscape: attributes is listed as a note.
  • Safety: <script>, on... event handlers, javascript: links, and files loaded from other addresses are flagged.

Examples

The sample file has five typical problems:

  • Error: fill="url(#fade2)" points to an id that does not exist (the gradient is called fade).
  • Error: two elements use id="card".
  • Warning: strok-width is a typo for stroke-width, so browsers ignore it.
  • Warning: onclick is an event handler.
  • Warning: no viewBox, so the file won't scale in CSS.

Errors, warnings, and notes

LevelMeaningExamples
ErrorThe file is broken or part of it can't workUnclosed tag, missing namespace, broken reference, duplicate id
WarningIt works, but something is probably wrong or riskyNo viewBox, unknown attribute, script, external file
NoteHarmless, worth knowingEditor metadata, foreignObject

Limitations

  • Attributes are checked against the full list of SVG attributes, not per element, so an attribute that exists in SVG but does nothing on that element is not flagged.
  • CSS inside <style> is not validated, except for references and imports.
  • The file is never drawn during validation. To look at it, use the SVG Viewer.

Frequently asked questions

What makes an SVG file invalid?

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.

Why does my SVG work in the browser but show errors here?

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.

Is it safe to validate an SVG with scripts?

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.

Does the validator fix the problems?

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.

  • XML ValidatorDeveloper Tools

    Checks XML for well-formedness and explains each syntax error.

  • SVG Formatter

    Indents SVG code for reading and editing without changing any values.