Design

SVG Not Showing? Fix Broken SVGs Fast (ViewBox, Fills, CSS, IDs)

Illustration of a broken SVG file with icons for common fixes like viewBox, fills, strokes, fonts to outlines, ID conflicts, and CSS overrides.
Illustration of a broken SVG file with icons for common fixes like viewBox, fills, strokes, fonts to outlines, ID conflicts, and CSS overrides.

SVG Troubleshooting: Why Your SVG Looks Broken (And Fixes)

SVG is supposed to be the “easy win”: crisp at any size, small file size, perfect for UI. But in real projects, SVGs break in annoying ways:

  • it doesn’t render at all

  • it renders but looks clipped

  • the colors disappear

  • strokes look wrong when resized

  • icons work on one page but not another

  • dark mode styling wrecks it

This guide gives you a practical, developer-friendly checklist to debug why your SVG isn’t showing and fix it quickly.

Internal reading (performance + general benefits):

ViewBox issues (the #1 reason SVG looks “missing”)

Symptoms

  • SVG shows as blank

  • SVG shows but is cropped

  • SVG scales weirdly or looks zoomed

What’s happening

SVG needs a coordinate system to scale correctly. That’s your viewBox. If it’s missing or wrong, the browser doesn’t know what portion of the canvas to show.

Fix

  1. Ensure the SVG has a viewBox like:

<svg viewBox="0 0 24 24"
  1. If you only have width/height but no viewBox, add it based on the original artboard size (common in exports).

  2. If it’s clipped, check:

  • clipPath / mask bounds

  • big negative coordinates or transforms

Fast test: open the SVG file directly in the browser. If it looks wrong there, it’s the file—not your app.

Missing fills (why your SVG is “invisible”)

Symptoms

  • paths exist but you see nothing

  • works on white background, disappears on dark background (or vice versa)

Common causes

  • fill="none" everywhere (common for stroke icons)

  • fill color matches background (e.g., white on white)

  • CSS overrides path { fill: none; }

Fix

  • If you expect a filled icon, make sure the paths have a fill:

    • fill="currentColor" is the safest for UI icons

  • If it’s a stroke icon, ensure stroke is set:

    • stroke="currentColor" and a visible stroke-width

Pro tip: Search the SVG for fill="none" and confirm it’s intentional.

Stroke scaling (why strokes look too thick / too thin)

Symptoms

  • strokes look fat when scaled down

  • strokes vanish at small sizes

  • inconsistent stroke weight across icons

What’s happening

Strokes scale when the SVG scales—unless you tell them not to.

Fix options

Option A: Let strokes scale (most common for icons)
Keep as-is, but design with stroke sizes that survive scaling.

Option B: Prevent stroke scaling (useful for diagrams)
Add:

vector-effect="non-scaling-stroke"

on relevant paths.

Option C: Convert stroke to outline
If you need pixel-consistent shapes (and no stroke math), outline strokes in your editor (Figma/Illustrator) so they become filled paths.

Fonts to outlines (why text looks wrong or missing)

Symptoms

  • text shows in Figma but not in the browser

  • wrong font renders (fallback)

  • spacing/kerning changes

  • text disappears in some environments

What’s happening

An SVG containing <text> relies on fonts being available where it’s rendered.

Fix

  • Convert text to outlines/paths before export (best for icons/logos)

  • Or embed fonts (heavier, not ideal for small UI assets)

Rule: if it’s UI iconography or a logo mark, outline text. If it’s a big infographic, consider keeping real HTML text instead.

ID conflicts (the sneakiest bug in real apps)

Symptoms

  • one icon breaks another icon

  • gradients/masks clipPaths stop working randomly

  • issues happen only when multiple SVGs are on the page

What’s happening

SVG uses IDs like:

  • id="clip0"

  • id="mask0"

  • id="gradient1"

When you inline multiple SVGs with the same IDs, they collide in the DOM.

Fix

  • Ensure IDs are unique per SVG (prefix them)

  • Use an SVGO plugin or build step that prefixes IDs

  • If using SVGR, enable “unique IDs” or “prefix IDs” behavior

Quick check: search for id=" in your SVG and see how generic it is.

CSS overrides (SVG looks fine, but your site breaks it)

Symptoms

  • SVG changes color unexpectedly

  • fills disappear only inside your app

  • hover states behave weirdly

Common causes

Global CSS like:

svg { fill: currentColor; }
path { fill: none; }
* { stroke: none; }

or Tailwind utility inheritance you didn’t intend.

Fix

  • Scope your CSS (avoid global SVG rules unless you mean it)

  • Set explicit attributes in the SVG for critical icons:

    • fill="currentColor" or fill="#111"

  • Prefer controlling icon color at the SVG root using currentColor, then style the parent element.

Quick fix checklist (save this)

When an SVG is broken, run this in order:

  1. Open SVG in a new browser tab (confirm file is valid)

  2. Check <svg> has a correct viewBox

  3. Confirm you’re not setting width/height = 0

  4. Search for fill="none" and ensure it’s intended

  5. Confirm stroke icons have stroke + stroke-width

  6. If text is used, outline text or provide font availability

  7. Search for id="clip" / mask / gradient → possible ID conflict

  8. Temporarily remove global CSS rules affecting svg, path, *

  9. If rendering via <img src="...">, confirm the path is correct and file isn’t blocked

  10. Re-export cleanly if needed (sometimes the export is the bug)

And if you’re using SVG heavily across the site, it’s worth it—SVGs are one of the easiest upgrades for performance and crisp UI when they’re clean.