SVG to JSX
Turn SVG into a React component with attributes like class fixed for you.
Input
Result
Everything runs in this browser. Your SVG is never uploaded.
Turn SVG into a React component with attributes like class fixed for you.
Everything runs in this browser. Your SVG is never uploaded.
Turns SVG code into JSX you can use directly in React. It changes class to className and attributes to camelCase.
Paste the SVG code.
Click convert.
Copy the component code.
class becomes className, and hyphenated attributes (stroke-width) become camelCase like strokeWidth. This tool changes them all at once.
Most of the time you can use it as is, but if the SVG has style tags or special attributes, give it a quick check.
In React, attributes that contain hyphens, such as class and stroke-width, must be written in camelCase like className and strokeWidth. The style attribute also has to be an object rather than a string. This tool fixes these parts automatically.
Unnecessary meta information in the code (comments and namespaces added by an editor) can often be deleted. To control the size with CSS, you can remove width and height and keep only the viewBox. Before pasting code from an outside source, check that it contains no scripts.
JSX differs from HTML, so SVG attribute names have to be written in camelCase. class becomes className, stroke-width becomes strokeWidth, fill-rule becomes fillRule, and xlink:href becomes xlinkHref (or href). A style="…" string has to become an object, and HTML comments and some namespaced attributes have to be removed.
This tool does these conversions automatically, so you can paste in an SVG you got from a designer as is and use it as a React component.
To make the color changeable, set the fill or stroke value to currentColor. Then it follows the text color of the parent element, so the color changes naturally on hover and in dark mode. For size, accepting width and height as props makes it easy to reuse.
Don't delete the viewBox. It's the key attribute that keeps the proportions when the size changes. If one component contains several SVGs, the same id can collide and tangle up gradients or masks, so make any ids unique.
SVGs exported from design tools contain a lot of unnecessary metadata and long decimal coordinates. Cleaning them up first with an optimization tool such as SVGO makes the code much shorter. After converting, check that the shape on screen matches the original and that the color changes as intended.
Adding aria-hidden="true" to decorative icons and <title> or aria-label to meaningful graphics improves accessibility. If the icons grow to dozens, an SVG sprite or a dedicated library is easier to manage than turning each one into a component.
They fall broadly into loading it as an image and putting it in directly as code, and if you want to change colors or animation from code, a JSX component is the most flexible.
This tool is for the last approach, turning SVG code into a component file.
Load with an img tag
Use as a CSS background
JSX component (inline)
If you paste the original SVG code as is, React may log a warning in the console that an attribute name is wrong, or the display may even break.
Below are problems you often meet when putting the original SVG straight into JSX. This tool fixes most of them automatically.
class="icon"
stroke-width="2"
style="opacity:.9"
xlink:href="#a"
If you set the fill or stroke value to currentColor, that SVG follows the surrounding text color (CSS color) as is.
Then the icon takes the button text color inside a button and the link color inside a link, and hover effects take just one line of color.
If you turn on the tool's "Change colors to currentColor" option, every fill and stroke value except none, transparent, inherit and url(...) is changed.
If you turn it on for a logo or illustration with several colors, all the colors collapse into one. Turn it on only for single-color icons.
If the original SVG already has width and height, the values passed as props can be overridden. This is because this tool places {...props} at the very beginning of the svg tag.
In JSX, attributes that come later win over earlier ones, so the width="24" written in the code takes priority over the width from props.
Turn it on only when you need to attach a ref to the icon. Most simple icons do not need it.
It is needed when passing the icon to tools that must grab the DOM element directly, such as tooltips, popovers or animation libraries. When turned on, the component is wrapped in forwardRef and a displayName is added.
From React 19, function components can receive ref like an ordinary prop, so forwardRef is no longer required. Check which React version you use first.
For a TypeScript project, it is safest to turn on the TS option and get .tsx code with props types, and for exports just follow your team's rule.
When the TS and props options are both on, the SVGProps<SVGSVGElement> type is attached, so standard SVG attributes such as aria-label and onClick get autocomplete.
Default export
Named export
If ids inside SVGs overlap on a page, they get tangled and gradients, clipPaths and masks can point to the wrong places.
Rendering the same icon several times creates the same id several times. Browsers usually reference the first one, so if the first icon is hidden or removed, the rest look broken too.
This tool does not change ids. If your SVG uses gradients or clipPaths, you need to check it yourself.
JSX is stricter than HTML, so an SVG that looked fine in the browser can cause syntax errors as a component.
Be especially careful when the SVG contains a style tag or text elements, because curly braces { } are interpreted as JavaScript expressions in JSX.
This tool's "Remove clutter" is a light cleanup that removes only comments, metadata and editor-specific attributes, not a professional optimization that also shrinks path data.
SVGs exported from design tools carry a lot of editing information, so this cleanup alone reduces them quite a bit. But if the path decimals are long, the file can still be large.
If you also want to trim the paths, it is best to run the open-source optimizer SVGO first and then convert with this tool.
The basic rule is to hide decorative icons from screen readers and to give meaningful icons a name.
This tool does not add accessibility attributes automatically. After conversion, you need to add them yourself to suit the purpose.
Decoration beside text
Button with only an icon
A graphic that conveys meaning
The viewBox sets the coordinate range of the SVG drawing, so without it the drawing is cropped instead of scaled when you change the size.
For example, an SVG with viewBox="0 0 24 24" says the picture was drawn on a 24-by-24 canvas. If you enlarge the width to 48px with CSS, the picture doubles in size too.
With the props option on, you can pass className and style from outside, so you can add effects without touching the icon code.
Used with currentColor, changing the parent element's color alone changes the hover color, and rotation or scaling can be handled with CSS transform.
From the text in the name box, only letters, digits and underscores are kept and the first letter is capitalized, and the result is used as the component name.
React only recognizes names that start with a capital letter as components, which is why this processing is done. If you enter only Korean, everything is removed and the default name Icon is used.
Even when you load or drag and drop an SVG file, the file is not uploaded to a server. It is read and converted only inside the browser.
If you have many icons, setting a rule such as adding Icon after the purpose, like CheckIcon and CloseIcon, makes them easier to search for when importing.