Skip to content

Instantly share code, notes, and snippets.

@derekwheee
Last active September 8, 2015 16:46
Show Gist options
  • Save derekwheee/10989841 to your computer and use it in GitHub Desktop.
Save derekwheee/10989841 to your computer and use it in GitHub Desktop.
Inline SVG with PNG fallback
<img src="/path/to/image.svg" onerror="this.onerror=null; this.src='/path/to/image.png'">
@derekwheee
Copy link
Author

If the SVG doesn't load (doesn't exist, or browser doesn't support SVG), the src attribute gets replaced with image.png. If that doesn't load, the img is set to null to avoid an infinite loop, and will just show up as a broken image.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment