Skip to content

SVG to React

Turn an SVG file into a React component. The tool converts attributes to their React names, such as stroke-width to strokeWidth and xlink:href to xlinkHref, turns style attributes into objects, drops the XML declaration and comments, and can pass the component props to the svg element with a TypeScript SVGProps type.

Reset

Frequently asked questions

What does the generated component look like?

A default exported function component that returns the svg element. With Pass props on, it accepts props and spreads them onto the svg, so you can set className, width, height or aria attributes where you use it.

Which attributes are converted?

Hyphenated presentation attributes such as stroke-width, fill-rule and stop-color become camelCase, xlink:href becomes xlinkHref, xmlns:xlink becomes xmlnsXlink and class becomes className. Attributes that are already camelCase in SVG, such as viewBox, keep their name.

Is the SVG optimized?

No. The tool keeps every element and attribute except the XML declaration, the doctype and comments. Run the SVG through the SVG Minifier first if you want smaller markup.

Can I use it without TypeScript?

Yes. Turn off TypeScript props type to get a plain JavaScript component without the SVGProps import.

What if my file contains several SVG elements?

The input must have exactly one svg root element. Split files with several root elements and convert each one.

Are width and height removed?

No. They are kept as written. Because props are spread after the original attributes, a width or height you pass to the component overrides them.

About OneClick Pro

OneClick Pro is a free collection of more than 150 web tools for everyday work: converting images and units, formatting and validating code, checking domains and SEO, and working with text, dates and numbers. Every tool runs without registration or subscription, and what you enter is only used to calculate your result and is never stored. Use it as a quick toolbox for one-off tasks, or bookmark the tools you rely on every day.