SVG to JSX
Convert SVG to JSX or a React component online: attributes are camelCased, editor metadata is removed and props can be passed to the <svg>.
Runs in your browser · Nothing uploaded · No sign-up
Something not working, or missing a feature? Send feedback
About the SVG to JSX
The SVG to JSX Converter turns an SVG file or icon into JSX or a ready React component. Attributes such as stroke-width and fill-rule are camelCased, class becomes className, inline styles become objects, and the metadata design tools add (Illustrator comments, Inkscape and Sketch attributes) is removed.
Conversion happens in your browser, so your files and records stay private.
How to use the SVG to JSX
- Paste the SVG code, for example from Figma, Illustrator or an icon set.
- Choose Component (with a name) or plain JSX.
- Keep "Pass props to <svg>" on to set className, size or aria-label where you use the icon.
- Turn on "Remove width and height" to size the icon with CSS, then copy the code.
Examples
Input
<?xml version="1.0" encoding="UTF-8"?> <!-- Generator: Adobe Illustrator 28.0 --> <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-check"> <circle cx="12" cy="12" r="10"/> <path d="m9 12 2 2 4-4"/> </svg>
Result
export default function CheckIcon(props) {
return (
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className="icon icon-check" {...props}>
<circle cx="12" cy="12" r="10" />
<path d="m9 12 2 2 4-4" />
</svg>
);
}The XML declaration and the Illustrator comment are dropped.
Input
<svg viewBox="0 0 24 24" width="24" height="24"><path fill-rule="evenodd" clip-rule="evenodd" d="M4 4h16v16H4z"/></svg>
Result
<svg viewBox="0 0 24 24" width="24" height="24"><path fillRule="evenodd" clipRule="evenodd" d="M4 4h16v16H4z" /></svg>
Input
<svg xmlns="http://www.w3.org/2000/svg" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" width="48" height="48" viewBox="0 0 48 48"><g inkscape:label="Layer 1" style="fill:#0f62fe;stroke-width:2"><rect x="4" y="4" width="40" height="40" rx="8"/></g></svg>
Result
export default function Logo(props) {
return (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48" {...props}><g style={{ fill: '#0f62fe', strokeWidth: '2' }}><rect x="4" y="4" width="40" height="40" rx="8" /></g></svg>
);
}Common mistakes
- Duplicate ids. Gradients, masks and clip paths use ids. Two copies of the same icon on a page share them, which can break the second one. Give each icon unique ids, for example with React's useId.
Works well with the SVG to JSX
- HTML to JSX: convert HTML around the icon.
- Image to SVG: turn a PNG logo into an SVG first.
- JavaScript Formatter: format the component with Prettier.
Frequently asked questions
Why pass props to the <svg>?
Then one component serves every size and colour: <CheckIcon className="size-4" aria-hidden="true" />. Props come after the original attributes, so they override them.
How do I change the icon colour with CSS?
Use fill="currentColor" or stroke="currentColor" in the SVG; the icon then takes the text colour of its parent, as in most icon sets.
Does it work for TypeScript?
Yes. For a typed component, annotate the parameter as props: React.SVGProps<SVGSVGElement>.
How is this different from SVGR?
SVGR is a build tool that converts SVG files during bundling. This converter gives you the component code once, to paste and edit, without any setup.
Related tools
JSON to CSV
Convert JSON arrays to CSV online with automatic column detection, nested object flattening and custom delimiters. Open the result in Excel or Sheets.
CSV to JSON
Convert CSV to a JSON array online with header detection, type inference and delimiter auto-detection. Turn spreadsheet exports into data for APIs and code.
JSON to XML
Convert JSON to well-formed XML online with a configurable root element and attribute support. Validate the input and download the XML file.
XML to JSON
Convert XML to JSON online, keeping attributes and turning repeated elements into arrays. Malformed XML is reported with its location.
JSON to YAML
Convert JSON to clean, human-readable YAML online. Turn API responses and package files into config for Kubernetes, Docker Compose or CI pipelines.
YAML to JSON
Convert YAML documents to formatted JSON online with syntax validation. Errors are reported by line, so broken indentation is quick to find and fix.