SVG to JSX
Paste SVG markup and get React-ready JSX with camelCase attributes, className, style objects, and TypeScript props.
// Error converting SVG
Conversions applied
Why raw SVG does not work directly in React: and how to fix it
If you have ever pasted an SVG icon directly into a React component and hit a wall of red errors, you know the problem. JSX is JavaScript syntax, not HTML: and SVG was designed long before React existed. The mismatch means every hyphenated attribute name (stroke-width, fill-rule, clip-path) is a syntax error in JSX, and reserved words like class conflict with JavaScript keywords.
The fix is a mechanical transformation: convert kebab-case to camelCase, rename class to className, convert style strings to objects. This tool does all of that automatically, producing a clean, reusable React component that accepts props and can be customized with className, onClick, or any SVG attribute. Adding TypeScript support gives you full IntelliSense across your entire codebase.
How to convert SVG to JSX: step by step
- 1Paste your SVG markup
Copy the SVG code from your editor or icon library and paste it into the input area on the left. You can also drag and drop an .svg file. - 2Set your component name
Type a PascalCase name for your React component: for example MyIcon or LogoSvg. The output will export that name. - 3Toggle TypeScript props
Enable TypeScript props to get an interface that extends React.SVGProps<SVGSVGElement> and a React.FC type annotation, ready for strict TypeScript projects. - 4Copy the JSX output
The right panel shows the converted component in real time. Click Copy to grab it and paste it directly into your React or Next.js project. - 5Drop it into your project
Paste the component file into your src/components/icons/ folder. The {…props} spread means callers can pass className, onClick, size, and any SVG attribute through.
Related Tools
Gradient Maker
Build linear, radial, and conic CSS gradients visually with color stops and live preview.
Box Shadow Maker
Compose multi-layer box shadows with X/Y offset, blur, spread, color, and inset controls.
Color Palette Generator
Generate complementary, analogous, triadic, and other harmony palettes. Export as CSS vars, SCSS, or JSON.
CSS Grid Generator
Configure grid-template-columns, rows, gaps, and alignment visually. Copy ready-to-use CSS.
Frequently Asked Questions
- Why do SVG attributes need to be converted for JSX?
- React's JSX is JavaScript, and JavaScript property names cannot contain hyphens. Attributes like stroke-width and fill-rule must become camelCase: strokeWidth and fillRule. Similarly, class conflicts with the JavaScript keyword class, so it becomes className in JSX.
- What conversions does the tool apply?
- The tool converts all SVG-specific kebab-case attributes to camelCase (strokeWidth, fillRule, clipPath, etc.), converts class to className, converts inline style strings to JavaScript objects, maps xlink:href to href, and removes Inkscape/Sodipodi editor namespaces.
- Why does the component spread {...props} onto the SVG element?
- Spreading props lets the parent component pass any SVG attribute: className, onClick, aria-label, width, height: without the icon component needing to explicitly declare each one. This is the standard React icon component pattern.
- Can I use this with TypeScript?
- Yes. Enable the TypeScript props toggle to get an interface extending React.SVGProps<SVGSVGElement> and a React.FC annotation. This gives you full type safety and autocomplete for every SVG attribute.
- Does the converter handle style attributes?
- Yes. A style string like style='fill: red; stroke-width: 2px' becomes style={{ fill: 'red', strokeWidth: '2px' }}: a JavaScript object that React expects.
- What happens to Inkscape and editor-specific attributes?
- The tool silently strips attributes and namespace declarations added by Inkscape (inkscape:label), Sodipodi, and similar editors because they are not valid JSX and serve no browser purpose.
- Can I convert multiple SVG icons at once?
- Currently the tool converts one SVG at a time. For batch conversion of many icons, consider running SVGR in your project's build pipeline.
- Does the tool handle defs, gradients, and clipPaths?
- Yes. The converter preserves defs elements and all their children so gradients, patterns, filters, and clipPath definitions are kept intact in the output component.
AlteredIdea vs alternatives
vs other online tools: Everything runs in your browser: private, instant, no account needed.
vs desktop apps: No install required. Works on any device.
vs paid tools: Completely free, unlimited use.