SVG to JSX: Why Developers are Ditching <img> Tags in React
Stop treating vectors like static JPEGs. Learn how converting SVGs to React components unlocks total design control and superior web performance.
By Cloudy Convert
Practical guides from the Cloudy Convert team on files, formats, privacy, and digital workflows.

Why the <img> Tag is Holding You Back
In the early days of web dev, the <img> tag was the gold standard for everything. But for modern React applications, it creates a "silo" effect. When you load an SVG via a source path, it lives in the Shadow DOM—completely unreachable by your application's CSS or logic.
"Using an img tag for an SVG is like buying a Ferrari but never being allowed to open the hood."
The Engineering Case for Inline JSX
Interactive States
Native support for onClick, onMouseEnter, and complex animations using Framer Motion.
Fewer Asset Requests
Inline icons can avoid separate image requests, but measure bundle size and loading behavior against your project's performance goals.
Tailwind Integration
Apply classes like 'fill-primary' or 'hover:scale-110' directly to your icon components.
Accessible Markup
Add titles, labels, and appropriate ARIA attributes when the icon's meaning needs to be exposed to assistive technology.
Mastering Tailwind CSS with JSX SVGs
This is where the magic happens. By converting your SVG to JSX, you can use Tailwind's group-hover and transition utilities to create professional UI interactions without writing a single line of custom CSS.
*Tip: Use the fill="currentColor" attribute in your SVG paths to make them automatically inherit the text color of their parent container.*
Bringing Icons to Life with Animation
When an SVG is trapped inside an <img> tag, it’s a black box. You can move the box, but you can’t touch what's inside. By converting to JSX, every path, circle, and polygon becomes a DOM element you can animate individually.
Imagine a "Sync" icon where the arrows actually rotate while loading, or a "Checkmark" that draws its own path when a task is completed. Using libraries like Framer Motion, this becomes trivial:
The Manual Conversion Headache
If JSX is so much better, why doesn't everyone use it? Because manual conversion is a nightmare. Standard SVG files exported from Figma or Illustrator are filled with "junk" code and syntax that React hates.
The React Conflicts
- •
classmust beclassName - •
stroke-widthmust bestrokeWidth - •
style="stop-color..."must be an object
The Bloat Factor
- •
<metadata>tags from Figma - • Hardcoded IDs that clash in the DOM
- • Unnecessary
xmlnsdeclarations
Impact on LCP and Core Web Vitals
In 2026, Google’s search rankings are heavily influenced by Core Web Vitals. Every <img> tag on your page represents an additional HTTP request.
When you inline an SVG as JSX, you can avoid a separate request for that asset, but the markup becomes part of the JavaScript or HTML payload. Whether this improves Largest Contentful Paint (LCP) depends on bundle size, loading order, caching, and the role of the icon, so measure the result rather than assuming a universal gain.
Remove the Manual Conversion Step
Once you have decided an icon belongs in the component layer, use the converter to handle JSX naming and structure, then review the output before adding it to your library.
Convert an SVG to JSXDevelopment Workflow: Before & After
Raw SVG (Bloated)
Clean JSX (Optimized)
Type-Safe Icons: Leveraging TypeScript
One of the biggest advantages of moving from .svg files to JSX is Type Safety. Standard <img> tags are "dumb"—they don't know if you're passing a valid width or a misspelled attribute.
By converting to JSX, you can extend React's native SVG types. This gives your team instant Autocomplete and prevents bugs before they hit production.
// Define a reusable Icon Interface
The "Barrel" Pattern: Organizing Your Library
As your project grows, you might end up with 50+ icon components. Importing them individually can clutter your files. The Barrel Pattern allows you to export all icons from a single entry point.
This keeps your "Imports" section clean and makes it much easier for other developers to find available icons in your design system.
Security Check: JSX vs. dangerouslySetInnerHTML
Many developers try to load SVGs dynamically by fetching raw strings and injecting them using dangerouslySetInnerHTML. This is a massive security vulnerability that can lead to Cross-Site Scripting (XSS) attacks if the SVG source is compromised.
The Security Advantage
Converting SVGs to JSX gives you code you can review and control, but it is not a substitute for sanitization. Treat third-party SVGs as untrusted input, remove unsafe elements and event attributes, and review the generated component before shipping it.
In short: JSX can be more flexible, but its security depends on how the source is validated and what the generated component is allowed to render.
When should you stick to `<img>`?
Engineering is about trade-offs. You should NOT convert to JSX if:
- The SVG is extremely large (e.g., a complex illustration with 5,000+ paths). This can bloat your JavaScript bundle and slow down React's reconciliation.
- The SVG is user-generated content (Security risk: potential XSS if not sanitized).
- You need the image to be easily cached by the browser's CDN as a static asset.



