To validate an SVG, first check that it is well-formed XML with an <svg> root. Then preview it, inspect the viewBox and internal references, scan for unsafe markup, and review accessibility. One green check cannot prove all five.
What does SVG validation actually mean?
SVG is an XML-based graphics language. The SVG 2 conformance rules describe a stand-alone SVG file as well-formed XML with an svg root. That is the starting point, not the whole review.
The W3C also notes that an image/svg+xml processor expects well-formed XML but cannot assume the document is valid against a particular DTD or schema. In practice, “validate SVG” can refer to several different checks.
| Check | What it finds | What it does not prove |
|---|
| XML parsing | Broken tags, quotes, entities, and nesting | Correct appearance or safe content |
| Browser preview | Blank output, clipping, and obvious rendering changes | Consistent output in every app |
| Safety review | Scripts, event handlers, and unsafe links | A complete upload security policy |
| Accessibility review | Missing names, roles, ARIA references, and duplicate IDs | Full WCAG conformance in its final page context |
How to validate an SVG file step by step
- Parse the XML. Open the file in the SVG code editor. A missing closing tag, unquoted attribute, or stray character can stop the document from parsing.
- Confirm the root element. A stand-alone file should have an
<svg> root in the SVG namespace, normally written as xmlns="http://www.w3.org/2000/svg". - Check the canvas. Inspect
viewBox, width, and height. The SVG 2 viewBox definition requires four numbers, and zero width or height disables rendering. - Preview the result. Look for blank artwork, clipping, lost gradients, missing fonts, and unexpected external assets. Use the SVG viewer when you want inspection without editing.
- Review links and executable markup. Unknown SVG can contain scripts, event attributes, or remote references. Run it through the SVG cleaner before publishing or converting it.
- Check its final use. If the graphic conveys meaning, review its name and ARIA relationships with the SVG accessibility checker. Then test it where it will actually appear.
Common SVG errors and practical fixes
XML parsing error
Check the line named in the error. Look for a missing closing tag, mismatched quote, bare ampersand, duplicate attribute, or content pasted outside the root element. Fix one syntax error at a time because the first error can hide the next one.
The SVG parses but appears blank
Check for a missing or malformed viewBox, zero width or height, artwork positioned outside the canvas, white artwork on a white background, or a broken url(#id) reference.
The SVG works in one app but not another
External fonts, CSS, linked images, filters, masks, and editor-specific metadata do not travel equally well. Keep the original, clean a copy, and compare the result in the browser and the destination app.
The file is valid but not safe to publish
XML validity does not make active content harmless. Remove scripts, inline event handlers, unsafe URLs, and unsupported elements. If your product accepts user uploads, enforce a server-side allowlist too.
Does every valid SVG need a viewBox?
An SVG can parse without a viewBox, but responsive scaling becomes harder and the artwork may be clipped or sized unexpectedly. The attribute contains min-x, min-y, width, and height. Use the SVG viewBox editor to inspect or fit the canvas around existing artwork.
Validation is not the same as accessibility testing
A parser cannot decide whether an image is meaningful in its page context. W3C guidance recommends an accessible name for SVG content that people need to understand, using a direct child <title>, aria-label, or aria-labelledby. Decorative graphics should be hidden from assistive technology when appropriate.