Validate SVG: viewBox, XSS Risks, and A11y Hints
What this linter is (and is not)
It is a practical, client-side checklist for common shipping issues.
It is not a full W3C suite replacement or a formal security audit. Treat findings as signals: fix, sanitize, re-validate.
Checks that matter in production
| Area | Why it matters |
|---|---|
| XML syntax | Broken markup fails silently in some pipelines and loudly in others |
| viewBox | Without it, CSS width/height scaling gets unpredictable |
| Security hints | Scripts, handlers, risky URLs → sanitize before embed |
| A11y notes | Title/desc/role reminders for meaningful vs decorative icons |
Step 1: Paste the candidate SVG
- Open SVG Validator & Linter.
- Upload or paste the file you are about to merge.
- Prefer the same bytes that will hit production (after export, not a half-edited buffer).
Step 2: Read findings with intent
- Syntax errors — fix first; nothing else is trustworthy until XML parses
- viewBox — add or repair; pair with Crop if framing is wrong
- Security — run Sanitizer on untrusted or user-generated SVG
- A11y — decorative UI glyphs often need
aria-hidden="true"on the host; meaningful graphics need text alternatives
Step 3: Fix, then re-check
Update markup → validate again → only then optimize/minify. A clean lint report is a cheap gate in code review (“paste validator screenshot or green run”).
Practical recipes
Third-party icon from the internet
Validate → Sanitize → Optimize → commit.
Responsive icon looks cropped in CSS
Validator flags viewBox → fix or trim → re-check.
Design export with leftover scripts? Unlikely but
Security hints → Sanitizer → never inline raw.
Component library PR checklist
Validator + license note on the Iconify set page.
FAQ
What does the validator check?
XML syntax, viewBox issues, security-related constructs, and accessibility hints.
Is this the same as a W3C markup validator?
No—it is a practical browser-side linter for common SVG shipping issues, not every formal validation suite.
What if security hints appear?
Review the file and consider the SVG Sanitizer before embedding untrusted content.
Are files uploaded?
No. Analysis is local.
Quick checklist
- Open SVG Validator
- Paste production-bound SVG
- Fix syntax → viewBox → security → a11y
- Sanitize if untrusted
- Re-validate, then optimize
Try it now
Open the free SVG Validator & Linter, paste an icon from your last PR, and clear the boring failures before they hit users—without uploading. Pair with the SVG Sanitizer whenever the source is not fully trusted.
Recommended
How to Edit Icons with SVG Editor
Customize open-source and local SVG icons in SVGForge’s browser-based SVG Editor—change colors, layers, and size, then export SVG, JSX, PNG, and more.
Read ArticleHow to Keep Icon Bundles Small Without Barrel Imports
Wildcard icon imports can add megabytes to your client JS. Learn safe import patterns, bundler checks, and when a curated SVG collection beats an npm icon pack.
Read ArticleOptimize SVG Assets Before Production: A Practical Checklist
A ship-ready SVG checklist: clean markup, theming with currentColor, strip metadata, choose the right delivery mode, and verify visuals after compression.
Read Article