Cloud background
Rotating wheel
Cloudy Convert
Web Development• 6 min read

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.

SVG to JSX Conversion Comparison for React Developers

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

  • class must be className
  • stroke-width must be strokeWidth
  • style="stop-color..." must be an object

The Bloat Factor

  • <metadata> tags from Figma
  • • Hardcoded IDs that clash in the DOM
  • • Unnecessary xmlns declarations

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 JSX

Development 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.

Step 1: Create index.ts
Step 2: Clean Imports

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.

Frequently Asked Questions

An `` tag just displays a static image file, which means you can't easily change its color or style with CSS. An inline SVG component embeds the SVG's code directly into your HTML, allowing you to manipulate its properties (like `fill` and `stroke`) with CSS or JavaScript props, making it dynamic and interactive.

Once you have an SVG as a React component, you can pass Tailwind classes directly to it. For example, you can use `className='fill-primary hover:fill-blue-500'` to control its color on hover. This is impossible with an `` tag.

For a few icons, inlining is often better as it avoids an extra network request. For a very large number of icons, a sprite sheet can be more performant as it's cached after the first download. Our tool is perfect for the inlining approach, which is ideal for most modern web apps using component-based frameworks.

Absolutely. This is a major advantage. Because the SVG's elements (``, ``, etc.) are part of the DOM, you can target them with CSS animations or JavaScript libraries like Framer Motion to create sophisticated interactive animations.

Yes, but usually by a negligible amount, especially for icons. When you use our tool's 'Optimize SVG' option, it strips out unnecessary code, making the resulting JSX very small. The performance gain from eliminating an HTTP request almost always outweighs the tiny increase in bundle size.

Related Posts

Have an idea for a new tool?

We're always looking to build useful utilities for the community. If there's something you'd love to see, let us know!