JSX to SVG Converter - Convert React JSX Components to SVG Files Online
Turn a React icon component written in JSX back into a standalone SVG file, with React prop names changed back to SVG attributes and default prop values filled in.
Loading JSX to SVG Converter...
JSX to SVG Converter - Export React Components to Standard SVG
A lot of icons only exist as JSX components by now: copied out of an icon pack, generated by SVGR years ago, or drawn straight in React. When a designer, a docs page or a Vue or plain HTML project needs the file itself, this page gives it back. Paste the component and you get the markup of its <svg> element with React's spellings undone, so strokeWidth is stroke-width again and className is class, while viewBox keeps its capital B because that is how SVG spells it. Need the opposite? The SVG to JSX converter goes the other way.
How to Convert JSX to SVG - Step by Step Guide
Paste JSX Component Code
Paste the whole component file or only the <svg>…</svg> part, or upload a .jsx or .js file. Imports, PropTypes, a class with a render() method, require() and module.exports are all fine. If you're moving the project to TypeScript, the JSX to TSX converter adds the types, and the JSX validator helps when the code won't parse.
export default function Layers({ size = 24, ...props }) {
return (
<svg width={size} height={size} viewBox="0 0 24 24" fill="none" {...props}>
<path d="M12 2L2 7L12 12" stroke="currentColor"
strokeWidth={2} strokeLinecap="round" fillOpacity="0.8" />
</svg>
);
}The First <svg> Comes Out as SVG
Shortly after you stop typing, the first <svg> in your code is written out. The default value of size becomes width="24" and height="24", {2} becomes "2", and the namespace a standalone file needs is added at the front. {...props} can't be known without running the component, so it is left out and mentioned in a note. Here is the result for the code above:
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
<path d="M12 2L2 7L12 12" stroke="currentColor" stroke-width="2" stroke-linecap="round" fill-opacity="0.8" />
</svg>Check What Was Renamed and What Was Left Out
Only props that React spells differently are renamed. Stroke, fill, font, clip and marker props get their dashed SVG names, className becomes class and xlinkHref becomes xlink:href. viewBox, preserveAspectRatio and the other attributes SVG already writes in mixed case stay as they are. Anything that depends on a running app, such as props.color, Logo.defaultProps, a .map() over data or another component like <Badge />, is listed under the output, and left-out children are marked with an XML comment. Event handlers are always removed. For markup that isn't an icon, the JSX to HTML converter is a better fit, and HTML to JSX covers the reverse.
// Renamed:
strokeWidth → stroke-width
fillOpacity → fill-opacity
fontFamily → font-family
className → class
xlinkHref → xlink:href
// Kept as written:
viewBox, preserveAspectRatio, gradientUnits, data-*, aria-*Copy or Download the SVG File
Copy the SVG, or download it as icon.svg. The output has been through an XML parser before you see it, so it opens as an image in a browser or a design tool. Values that were left out still need filling in by hand. To clean up the source before converting, try the JSX formatter or the JSX minifier. Converting a .tsx file? The TSX to SVG page uses the same converter.
Frequently Asked Questions
How do I get an .svg file out of a React icon component?
Paste the component into the input editor, or upload the .jsx or .js file. It can be a function component, an arrow function, a class with a render() method, or a file that uses require() and module.exports. The first <svg> element in the code is written out as plain SVG markup shortly after you stop typing, and you can copy it or download it as icon.svg.
Does it turn every camelCase attribute into kebab-case?
No, and that is on purpose. Only the props that React spells differently from SVG are renamed: className goes back to class, xlinkHref and xlink:href both end up as xlink:href, and presentation props like strokeWidth, strokeLinecap, fillOpacity, stopColor and fontFamily get their dashed names. SVG itself uses mixed case for some attributes, so viewBox, preserveAspectRatio, gradientUnits and stdDeviation are left alone. Dashing those would break the icon. data-* and aria-* attributes pass through as written.
My icon takes props like size and color. What ends up in the SVG?
The converter never runs your JavaScript. It reads values it can see in the source: literals such as {2}, template strings, string concatenation, const and let declarations, and default values in the props, like function Logo({ size = 24 }). Something like props.color || 'red', a prop with no default, {...props}, a .map() loop or a condition is only known at run time, so it is left out and named in a note under the output. Logo.defaultProps and PropTypes are not read either, so if your icon relies on defaultProps, move those values into default parameters or fill them in afterwards.
What happens to style objects, event handlers and other React-only props?
style={{ strokeWidth: 2, opacity: 0.5 }} is written as a CSS string, with px added to plain numbers the way React adds it. onClick, onMouseEnter and every other on* handler are removed, because an SVG file has nowhere to keep a JavaScript function. key, ref and dangerouslySetInnerHTML are dropped too. A <script> element or a javascript: link is kept, but you get a warning about it.
Will the file open in a browser, Figma or Illustrator?
React lets you leave xmlns off an inline <svg>, but a standalone .svg file without it shows up as plain text instead of an image. The converter adds xmlns (and xmlns:xlink when xlink: attributes are used) and checks the result with an XML parser before showing it. Anything that was left out, like a fill that came from a prop, still has to be filled in by hand, so read the notes before you hand the file over.
What if my JSX has a syntax error?
You get the line and column the parser stopped at, with that line shown underneath, instead of half-converted output. If you pasted JSON, an .svg file that is already plain SVG, or JavaScript without any JSX in it, the message says so.
Can I paste a TypeScript component here?
Yes. The same parser reads TypeScript, so a .tsx file works on this page as well. The TSX to SVG page is the same converter with TypeScript wording.
Related Tools
JSX Formatter
Format and beautify JSX/React code with proper indentation
JSX Fixer
Fix broken JSX automatically, repair React component syntax errors, unclosed tags, and invalid expressions
HTML to JSX Converter
Convert HTML to JSX/React format instantly
Markdown to JSX Converter
Convert Markdown to React JSX components for blogs and documentation
JSX Validator
Validate JSX syntax and React component structure
JSX Minifier
Minify JSX/React code for production builds
JSX to TSX Converter
Convert JSX to TypeScript TSX with type annotations
JSX to HTML Converter
Convert React JSX to standard HTML