SVG to JSX Converter

Convert raw SVG code to modular, React or React Native compliant components.

SVG Source Input
JSX Component Output
Live Graphic Preview
Load Sample Templates:
How it conversions work:
• Attributes like stroke-width map directly to React camelCase (strokeWidth).
• class and for are formatted into className and htmlFor.
• Inline Style strings are beautifully split into declarative JavaScript objects.
• React Native SVG: Supports output targeting mobile apps via the specialized react-native-svg library framework elements.
← All 140+ Free Tools 💻 Developer & Code Tools

About SVG to React JSX / TSX Converter

Convert SVG to JSX — a React component in JSX or TypeScript (TSX), or React Native SVG code. Attributes are renamed for React (class → className, stroke-width → strokeWidth), inline styles become objects, fixed width and height can be removed so the icon scales, and {...props} is spread onto the root.

How to use it

  1. 1Paste raw SVG code into the left editor.
  2. 2Configure component name, TypeScript types, and prop forwarding.
  3. 3Copy your clean React JSX component.

What changes during conversion

SVG JSX
class="icon" className="icon"
stroke-width="2" strokeWidth={2}
fill-rule="evenodd" fillRule="evenodd"
xlink:href="#a" xlinkHref="#a"
style="fill:red" style={{ fill: 'red' }}
<!-- comment --> removed

Example output

export function CheckIcon(props) {
  return (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" {...props}>
      <path d="M5 13l4 4L19 7" strokeWidth={2} strokeLinecap="round" />
    </svg>
  );
}

Best practices for icon components

  • Use currentColor for fill or stroke so the icon takes the text colour from CSS.
  • Remove width/height and keep viewBox so the size is controlled by CSS or props.
  • Spread props so you can pass className, aria-label or onClick.
  • Accessibility: decorative icons should have aria-hidden="true"; meaningful icons need an accessible label.
  • Clean first: exported SVGs from design tools often contain IDs, metadata and hidden layers; "Deep Clean" removes much of it.

For React Native, the output uses components from the react-native-svg package (Svg, Path, Circle).

Making icon components reusable

After converting an SVG to a React component, a few small changes make it work like a proper icon:

export function CheckIcon({ size = 24, title, ...props }) {
  return (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none"
         stroke="currentColor" aria-hidden={title ? undefined : true} role={title ? 'img' : undefined} {...props}>
      {title && <title>{title}</title>}
      <path d="M5 13l4 4L19 7" strokeWidth={2} />
    </svg>
  );
}
  • currentColor lets the icon take the text colour around it.
  • A size prop keeps width and height in one place.
  • Spreading ...props allows className, onClick and other attributes.
  • Accessibility: decorative icons get aria-hidden; meaningful ones get a title.

Inline SVG, img tag or icon font?

Inline JSX icons can be styled and animated with CSS and add no extra network requests, which makes them the usual choice in React apps. Large illustrations are better as separate .svg files loaded with <img>, so they are cached and do not bloat your JavaScript bundle.

Clean the SVG before converting

SVGs exported from Figma or Illustrator often contain editor metadata, hidden layers and fixed colours. Remove what you don't need in the SVG editor, replace fixed fills with currentColor so CSS can recolour the icon, then convert it here. For a PNG version of the same icon, use the SVG option of the file converter.

Frequently Asked Questions

How do I convert an SVG to a React component?

Paste the SVG code, set the component name and options such as TypeScript and prop forwarding, then copy the generated component.

Why does React complain about my SVG attributes?

React uses camelCase for attributes: stroke-width must be strokeWidth and class must be className. The converter renames them for you.

Can it output TypeScript (TSX)?

Yes. Tick TypeScript (TSX) to get a typed component, ready for Next.js, Vite or other React projects.

Does it work with React Native?

Yes. The React Native option outputs code for the react-native-svg library, which you need to install in your app.

How do I change the icon colour with CSS?

Replace fixed colours with currentColor. The icon then uses the text colour of its parent, so color: red recolours it.

How do I make the icon resize?

Tick Remove Dimension Attributes so the fixed width and height go and the viewBox stays. Then set the size with CSS or by passing width and height props.

Can I animate the converted icon?

Yes. Add CSS animations or a library such as Framer Motion to the component or to its paths.

Is my SVG uploaded?

No. The conversion runs in your browser.