By Tim King · Updated
SVG Validator
Line-Numbered Report of Unclosed Tags, Bare Ampersands, Path Data and Duplicate IDs
OneTask is free, with no sign-up, and built by one person.
If this tool saved you time, a coffee helps keep new ones coming.
How the SVG Validator works
This SVG validator checks markup in the browser and points to the line of each fault. Paste an SVG file or fragment and every problem is listed with its line number: elements never
closed, ampersands not escaped, path data with a stray character, a viewBox with three numbers,
ids used twice, fill="url(#grad)" pointing at a gradient that does not exist, clippath where
clipPath was meant, and a missing xmlns. Nothing is uploaded — the check runs in your browser.
A broken SVG behaves differently depending on where you put it. Inline in an HTML page, the
browser's forgiving HTML parser patches it up and it mostly renders. The same file used in
an <img>, a CSS background or a favicon goes through a strict XML parser instead, and it
either shows nothing or shows the "XML parsing error" page. Illustrator, Figma and Inkscape
export clean XML, but as soon as someone hand-edits a file, or a template stitches one
together, the strict cases start failing. This checker applies the strict rules, so what
passes here works everywhere.
Why it matters. SVG is now the default format for logos, icons and simple
illustrations on the web. It is resolution-independent and often a fraction of the size of
an equivalent PNG. That makes it a dependency of many other things. Icon systems built on
<use href="#icon"> sprites fail silently when an id is wrong. Email clients and
image-processing pipelines reject malformed files outright. Design-token pipelines,
React's SVGR loader and build tools such as SVGO all start by parsing the XML, so one
unclosed tag can break a whole build. Many upload forms and CMSs refuse any SVG that
contains <script>, because an SVG opened directly in a browser can run code.
XML rules come first. Every element must be closed, either with an end tag or a
trailing slash; SVG has no optional closing tags. Attribute values must be quoted, every
attribute needs a value, a bare & in text must be written &, and there can be only
one root element. A comment cannot contain --. If there is an <?xml ?> declaration it
must be the very first thing in the file, and a stray blank line before it is enough to
break the document. Names are case-sensitive, so <clippath>, <lineargradient> and
viewbox are errors. They are the most common reason a hand-written SVG silently does
nothing.
Shapes are checked for the attributes they need. A <path> without d, a <circle>
without r, a <line> without both ends, or an <image> or <use> without href is an
error. A <rect> or <ellipse> missing a size is legal but draws nothing, so it gets a
warning. Path data is checked for stray characters, a missing initial moveto and malformed
numbers such as 1.2.3. A polygon's points must contain an even count of numbers.
Coordinates, radii, sizes, stroke-width and opacities must parse as numbers, sizes
cannot be negative, and opacity must be between 0 and 1.
References are resolved. Every id is collected. Then every href="#…",
xlink:href and url(#…) in a fill, stroke, filter, mask, clip-path or marker is checked
against that list. A reference to a missing id is the classic "my gradient renders as
black" bug, and it is reported on the line where the reference is made. Duplicate ids are
errors because the second element can never be reached. Ids that start with a digit get a
warning, because they break CSS selectors and url(#…) in some browsers. A <stop>
outside a gradient, a <tspan> outside <text> and filter primitives outside <filter>
are structural errors.
Colours and inline styles. Hex colours must have 3, 4, 6 or 8 digits. A bare word in
fill, stroke or stop-color must be a real colour name, while none, currentColor,
url() and the functional colour syntaxes are accepted. A style attribute is split on
semicolons, and each declaration must contain a colon.
Reading the SVG validator report
The summary shows the number of Elements and Ids found, the count of Errors and Warnings, and a one-line Result. The table below it lists each problem with its line number, its level and a message.
- Errors break the file in at least one context. Fix them all before shipping; each message names the element or attribute at fault.
- Warnings mark things that work today but will cause trouble somewhere else.
- Valid, with warnings is a normal result for exported artwork. Read the list and fix the ones that apply to how you will use the file.
Warnings worth acting on. A root <svg> without xmlns renders inline but fails as a
standalone file or in <img>. Without a viewBox the graphic will not scale to its
container. xlink:href is deprecated in favour of plain href, and using any xlink:
attribute without declaring its namespace is an error. <script> is flagged because it
runs inline but is blocked in <img> and CSS. For accessibility, the root should have a
<title> or aria-label, plus role="img", or aria-hidden="true" if the graphic is
decorative. A DOCTYPE is unnecessary and should be removed.
Tips. Fix errors from the top down, because a single unclosed tag can cause a cascade
of errors further down that all disappear once it is fixed. Run exported files through an
optimiser such as SVGO after they validate, not before, and check again afterwards, since
aggressive id minification can break references. If an icon renders inline but not as a
background image, the missing xmlns warning is almost always the cause.
What it does not do. It does not know which attributes are allowed on which element,
so a misspelling like strke is caught only if it is one of the checked names. It does not
validate transform syntax or filter parameters, and it does not render the graphic. Use
the SVG path visualizer in the related tools to see what a path actually draws.
FAQ
Does this send my SVG anywhere?
No. Everything runs in your browser and nothing is uploaded. Logos, icons and diagrams that are not yet public stay on your machine, and you can check files from a client's private repository without any of it leaving the tab.
It renders fine in my HTML page — why does it report errors?
Because inline SVG in HTML goes through the HTML parser, which repairs unclosed tags, ignores
case and tolerates bare ampersands. The same markup saved as a .svg file and used in an
<img>, a CSS background-image or a favicon is parsed as XML, where every one of those is a
fatal error. Fix them now and the file works in both places.
Why is a missing xmlns only a warning?
Inside an HTML document the <svg> tag is recognised without it. As a standalone file the
namespace is required — without xmlns="http://www.w3.org/2000/svg" the browser treats the
elements as unknown XML and draws nothing. Add it if there is any chance the file will be used
on its own.
What does "references #grad but no element has that id" mean?
Something — usually a fill="url(#grad)" or a <use href="#grad"> — points at an element with
id="grad" and there is none. Either the definition was deleted, the id was renamed, or an
optimiser stripped it. The fill falls back to black or the <use> draws nothing.
Can I paste just a fragment, without the outer svg tag?
Yes. The checker reports that the root element is not <svg> and skips the root-level checks
for xmlns, viewBox and title, but everything else — closing, references, path data, colours — is
checked as normal.
See also: all Formatters & Validators tools, Dev Utilities, Data & Encoding, Security & Identifiers, SEO, Accessibility, AI.
Related tools
XML Formatter
Indent messy XML or squash it to one line, with tag checking.
WCAG Checker
Find WCAG accessibility failures in pasted HTML, with the criterion each breaks.
URL Validator
Check a list of URLs for syntax errors, one per line.
0–60 Calculator
0–60 mph, 0–100 km/h and quarter mile from power and weight.
1920s Name Generator
Jazz Age names, from Chester Vanderbeck III to Millie Kowalski the flapper.