Common SVG Icon Mistakes and Fixes
The most common SVG icon mistakes in production UI and how to fix each one quickly with practical code examples.
If your SVG icons look blurry, refuse to change color, or scale incorrectly, you usually have one of these five issues.
1) Missing viewBox
Without viewBox, responsive scaling breaks.
<!-- Bad -->
<svg width="24" height="24">...</svg>
<!-- Good -->
<svg viewBox="0 0 24 24" width="24" height="24">...</svg>
2) Hardcoded fill and stroke
Hardcoded color blocks theming and hover states.
<!-- Better -->
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor">...</svg>
3) Using img when you need styling
<img src="icon.svg"> is fine for static display, but you cannot target internal paths with CSS.
Use inline SVG for interactive controls.
4) Over-optimized path precision
Aggressive path compression can deform icons at small sizes.
{
"plugins": [
{ "name": "convertPathData", "params": { "floatPrecision": 2 } }
]
}
5) No accessibility labels
Interactive controls need accessible names.
<button aria-label="Open settings">
<svg aria-hidden="true" viewBox="0 0 24 24">...</svg>
</button>
Test every icon at 16px and 24px. Most visual defects show up immediately at those sizes.
Quick debug checklist
- Confirm
viewBoxexists. - Replace fixed colors with
currentColor. - Switch to inline SVG for state styling.
- Re-run SVGO with safer precision.
- Add ARIA labels for icon-only controls.
Example icon for QA
tabler:settings•56pxRelated guides
Debug flow for faster fixes
When an icon bug appears in production, run this order:
- Inspect final rendered SVG in devtools.
- Confirm
viewBoxand dimensions. - Check for hardcoded colors.
- Verify delivery method (
inlinevsimg). - Re-test at 16px and 24px.
This usually identifies root cause in minutes.
Preventive standards
- lint or review for missing
viewBox - require
currentColorfor UI icons - document allowed export settings in design handoff
- keep one approved optimization profile
A small shared standard prevents repeated icon regressions.
Production hardening checklist
- include icon lint/review rules in PR template
- keep a small approved set of optimization configs
- document which components require inline SVG
- run visual regression snapshots for critical icon controls
Teams that document these basics early avoid repeated icon regressions in later releases.
Final note
Most SVG bugs are preventable with a short review checklist and a standardized export pipeline. Fix process first, then individual icons.
A short weekly icon QA pass is cheaper than recurring production bug fixes.
Make this checklist part of onboarding so new contributors avoid repeating the same mistakes.
Preventive standards are always cheaper than reactive bug triage.
Additional source references: 1 2 3.