inline svg vs img
Inline SVG vs <img>: which should you use?
If you’re choosing between inline SVG and the <img> tag, the decision is mostly about styling control vs simplicity. Inline SVG lives in the DOM so you can style fills/strokes and use currentColor. <img> is cache-friendly and clean, but you can’t reliably style internal SVG paths with CSS.
currentColor, hover, active, and per-path styling.Inline SVG
Best when the SVG is part of your UI system and needs to respond to theme colors, hover states, and component props.
- Target internal nodes (
path,circle,stroke,fill) - Use
currentColorfor themeable icons - Add
aria-label,<title>,<desc>for accessibility
- More DOM nodes and bigger HTML if repeated
- Requires sanitization for untrusted SVG markup
- IDs can collide if you inline the same SVG many times
<img> (file URL or data URI)
Best when you want a simple, cacheable asset that you place like any other image.
- Easy caching and reuse across pages
- Cleaner DOM (no inline markup)
- Standard accessibility via
alt
- Cannot style internal paths with CSS
- Theme color changes require separate files or preprocessing
- Data URIs can bloat CSS/HTML and are harder to debug
Quick decision rules
- You need themeable icons with
currentColor - You want hover/active states that change fills/strokes
- You need SVG-specific accessibility markup
- You need to tweak viewBox, IDs, or classes in-place
- You want maximum caching and reuse
- The icon is decorative and does not need theming
- You want minimal DOM and simpler components
- You’re embedding the same asset many times
How to choose between inline SVG and <img>
Use the preview on this page to validate the exact behavior you care about: theming with currentColor, styling constraints, and whether your SVG has any unsafe markup that should be removed before shipping.
- Paste or upload an SVG.
- Choose a use-case preset if you want output tuned for theming, caching, decorative icons, responsive logos, or single-file handoff.
- Enable currentColor if you want themeable icons.
- Compare previews and copy the snippet that matches your needs.
- Keep sanitization enabled for any untrusted SVG.
