SVG to React component
MEMBERSTurn an SVG into a JSX or TSX component with the right attribute names, style objects and passed props, without its scripts.
Canvas
Canvas
The code cannot be read. The canvas shows the last version that could.
Fill
Stroke
Text
Place and size
Effects
Nothing is selected. These are the properties of the drawing.
Drawing
Press an element to select it, arrows move it, Delete removes it, Ctrl D copies it. V selects, A edits points, P is the pen, R a rectangle, O an ellipse, T a text. Layers hold every element for the keyboard.
Code, live both ways
Code, live both ways
Weight
What the file weighs
All optimizations
Found a bug or missing something? Write to us
How it works
A component you can commit
Attributes get the names React expects, class becomes className, and a style attribute becomes an object. Props are spread on the root, so size, colour and handlers are passed from outside.
Scripts, event handlers, editor data and outside addresses are left out, because a component runs inside your application. Style sheets inside the file are kept as a string.
The name of the component comes from the title of the drawing. Optimize first to make it shorter; use currentColor in the drawing to let the text colour paint the icon.
Help
FAQ
Is the component a default or a named export?
A named export, export function Name(props), imported as import { Name } from './Name'. The typed version adds import type { SVGProps } from 'react' and gives props the type SVGProps<SVGSVGElement>, so every attribute of svg is checked.
How are xlink:href, aria and data attributes converted?
xlink:href becomes href, xml:space xmlSpace and tabindex tabIndex, and other hyphenated names such as stroke-width are joined into strokeWidth. aria- and data- attributes keep their hyphens, as React expects, and the namespace declarations of drawing programs are left out.
Is a component better than an img with an SVG file?
A component is drawn inside the page, so CSS and currentColor reach every path and props change it, but its code goes into the JavaScript of every page that uses it. An img with a .svg file is cached on its own and cannot be styled from outside, which suits large illustrations.