SVG to JSX

Convert SVG markup to a React component.

The SVG to JSX tool turns an SVG file's markup into a React component. It converts hyphenated attributes such as stroke-width to camelCase, can spread props onto the root svg element, and can add TypeScript types. It is useful for turning icons and illustrations from design tools into components.

What is an SVG React component?

SVG is an XML format for vector graphics, and browsers can embed it directly in a page. React can render inline SVG too, but JSX needs the attributes written in camelCase: stroke-width becomes strokeWidth, fill-rule becomes fillRule and class becomes className. Turning an icon into a component has two benefits. You can pass props such as width, height, className or aria-label to it, and you can style it with currentColor or CSS. A common pattern is a function that receives props and spreads them onto the root svg element, so the caller can override size and color. In TypeScript those props are usually typed as SVGProps<SVGSVGElement>. This tool performs that mechanical rewrite and wraps the result in a ready-to-export component.

How to use SVG to JSX

  1. Paste the SVG Put the full <svg>...</svg> markup in the SVG box.
  2. Pick options Choose JavaScript or TypeScript under Language and decide whether to tick Spread props on <svg>.
  3. Read the component Convert to JSX is the selected operation, so the React component box fills in as you type and updates when you change an option.
  4. Save it Copy the code or download it as Icon.jsx or Icon.tsx and drop it into your project.

Frequently asked questions

Why is my SVG rejected when it works in a browser as HTML?

This tool parses the input as strict XML. HTML parsing is more forgiving about unclosed tags and unquoted attributes, but XML is not.

Are style attributes converted?

Yes. A style string on any element becomes a style object with camelCase property names, as in the HTML to JSX tool.

Is the output compatible with React Native?

Not directly. React Native needs a library such as react-native-svg with its own component names. This tool outputs DOM SVG elements for React on the web.

Does it keep the xmlns attribute?

Yes, xmlns is kept as written. Other namespaced attributes are converted to camelCase.

Is my SVG uploaded?

No. The text is parsed in the page and stays on your device.