SVG to React Converter
Turn raw SVG markup into a reusable React component.
Turn raw SVG markup into a reusable React component. Enter your numbers and get an instant result.
Paste SVG markup and a component name, and the page emits a React component: the markup with its hyphenated attributes rewritten to camelCase, the XML declaration and comments removed, a props spread added to the svg element, and an import and two exports wrapped around it.
The conversion is text substitution, not a parse. Only the attributes on a fixed list are renamed — class, stroke-width, stroke-linecap, stroke-linejoin, fill-rule, clip-rule, font-family, font-size, viewbox, stop-color, stop-opacity and stroke-miterlimit — so a less common hyphenated attribute survives and will warn in React.
Nothing is validated and no component is compiled. A relative path, a CSS style string or a hyphenated attribute outside the list is copied as written, so the output is a starting point that should be rendered once before it is committed.
What is rewritten
Each listed attribute is replaced case-insensitively, so viewBox is normalised even when the source wrote viewbox. Comments and the XML prolog are removed, and the opening svg tag receives a props spread so the caller can set width, height, className or an aria label.
The component name you type becomes the exported identifier. If it is blank the page falls back to SvgIcon; a name that is not a valid JavaScript identifier is not corrected, and the emitted code will not compile until you fix it.
- Twelve attribute renames, case-insensitive
- A props spread on the svg element
- An import plus a named and a default export
What a real pipeline adds
A production icon pipeline would parse the SVG, convert every attribute through a mapping derived from the DOM, handle style strings as objects, escape text, and run the result through a compiler. This page does none of that, which is why its output is short enough to read in a code review.
The same input always produces the same output, so the page can be used to check what a rename list does to a particular icon. It cannot tell you whether the component renders, because it never mounts one.
How to use the name field
Type the component name into the Component Name box, using a valid JavaScript identifier; a blank name falls back to SvgIcon. Paste the markup into Raw SVG Code and the React Component panel rewrites as you type, with the props spread already on the svg element.
Scan the output for hyphenated attributes the twelve-rename list does not cover and for style strings, which stay strings: fix those by hand. Render the component once before committing, since the page never compiles what it emits.
What to Expect
Best for
- Turning a simple icon into a React component
- Seeing which attributes need camelCase before a manual pass
- A quick starting file for a design system
Not ideal for
- An SVG with style strings, filters or uncommon attributes
- A pipeline that must guarantee a compiling component
- Converting a whole icon set at once
What this tool keeps
- Path data and the drawing's geometry
- The twelve renamed attributes in their camelCase form
- Comments outside the markup, which are not part of the output
What may need cleanup
- Hyphenated attributes outside the rename list
- A style attribute, which stays a string rather than becoming an object
- A component name that is not a valid identifier
Common errors
- Pasting an icon whose style attribute carries the fill and finding it still a string
- Using a component name with a dash and getting code that will not compile
- Expecting the page to escape text content for JSX
Example use cases
- Adding a one-off icon to a React app
- Teaching the difference between SVG attributes and JSX props
- Preparing a component to hand-edit
Sample input
A 24-pixel SVG path with stroke-width, stroke-linecap and stroke-linejoin, converted with the component name SvgIcon.
Sample output
A component file importing React, exporting const SvgIcon, with camelCase attributes and a props spread on the svg element.
Who this is for
- React developers adding an icon
- Design-system maintainers
- Learners comparing SVG and JSX
Frequently asked questions
What does the SVG-to-React conversion rewrite?
Hyphenated attributes become camelCase, the XML declaration and comments are removed, a props spread is added, and an import and two exports wrap the component.
Does it guarantee a compiling component?
No. An SVG with style strings, filters or uncommon attributes may need a hand fix.
Can it convert a whole icon set?
No. It converts one SVG at a time.
Build custom tools for your store
Join the SDK program to create useful ecommerce utilities for your store.