Paste an SVG file or icon and get a ready-to-use React component. Attributes are converted to camelCase, inline styles become style objects, class becomes className and editor junk is stripped. Add props spreading, icon sizing, currentColor or TypeScript with one click.
Last updated:
Preview
Advertisement
Advertisement
How to use the SVG to JSX
Paste your SVG code, drop an .svg file on the editor or press Upload.
Name the component; it is filled in from the file name automatically.
Pick the options: component style, TypeScript, props spread, size handling and currentColor.
Check the output, which updates as you type, and the preview of your SVG.
Copy or download the component as a .jsx or .tsx file and import it in your React app.
SVG attributes and their JSX names
React uses the JavaScript (DOM property) spelling of attributes. For SVG that mostly means removing hyphens and colons and capitalising the next letter. The most common conversions:
SVG attribute
JSX prop
SVG attribute
JSX prop
class
className
stroke-width
strokeWidth
fill-rule
fillRule
clip-rule
clipRule
stroke-linecap
strokeLinecap
stroke-linejoin
strokeLinejoin
stroke-dasharray
strokeDasharray
stroke-opacity
strokeOpacity
fill-opacity
fillOpacity
stop-color
stopColor
clip-path
clipPath
font-family
fontFamily
text-anchor
textAnchor
dominant-baseline
dominantBaseline
xlink:href
xlinkHref (or plain href)
xml:space
xmlSpace
style="fill:red"
style={{ fill: 'red' }}
onclick="…"
removed: use onClick with a function
Attributes that are already camelCase in SVG, such as viewBox, preserveAspectRatio and gradientUnits, stay the same. data-* and aria-* attributes also keep their hyphens.
Using the component
Save the output as CabinIcon.jsx (or .tsx) and import it like any other component. With the props spread enabled, everything you pass lands on the <svg> element:
For icon sets, combine Icon: 1em × 1em with Use currentColor: the icon then follows the font size and text color of wherever it is placed, so one component works in buttons, menus and headings without extra props. Keep each icon's id values unique (for gradients and clip paths), because several copies of the same inline SVG on one page share the document's id namespace.
Frequently asked questions
Why can't I paste SVG directly into JSX?
JSX follows JavaScript DOM property names, not HTML attribute names. SVG attributes with hyphens or namespaces such as stroke-width, fill-rule and xlink:href must be written as strokeWidth, fillRule and xlinkHref, class must become className, and inline style must be an object. React warns about or ignores the original names.
How do I change the icon color from React?
Turn on Use currentColor. Every fill and stroke color is replaced by currentColor, so the icon takes the CSS color of its parent: <Icon style={{ color: 'tomato' }} /> or a className that sets color.
What does the props spread do?
It adds {...props} to the root <svg>, so anything you pass to the component, such as className, width, aria-label or onClick, is applied to the SVG and overrides the default attribute values.
What does icon size 1em do?
It sets width and height to 1em so the icon scales with the surrounding font size, like an icon font. The viewBox is kept (or created from the original width and height) so the drawing scales correctly.
Does it work with React Native?
The output is for React DOM. React Native needs the react-native-svg library, whose component names are capitalised (Svg, Path, Circle). The attribute conversion is the same, so you can rename the elements by hand.
Is my SVG uploaded?
No. The SVG is parsed and converted by your browser, and the preview is rendered locally as an image so scripts inside the file never run.
Are all the tools on FreeToolCabin tested for quality and accuracy?
Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.