UTILS.
100% in-browser
🎨

SVG to JSX Component

Turn raw SVG markup into a ready-to-use React component with camelCased attributes, prop spreading, and optional currentColor and forwardRef.

— output appears here —

About this tool

The SVG to JSX Component tool converts raw SVG markup into a clean React component, the way SVGR does, but entirely in your browser with nothing uploaded. Paste an icon exported from a design tool and get a component you can import and style. It parses the SVG with DOMParser and reports a clear error if the markup is malformed.

Every hyphenated or namespaced SVG attribute is camelCased to its React name — stroke-width to strokeWidth, fill-rule to fillRule, clip-path to clipPath, stop-color to stopColor, xlink:href to xlinkHref, xmlns:xlink to xmlnsXlink — while data-* and aria-* attributes are left as-is. Inline style strings become style objects, empty elements like path and circle are self-closed, and props are spread onto the root <svg {...props}> so the component stays configurable. Optional toggles let you replace hard-coded fill and stroke values with currentColor (so the icon inherits text color), strip the width and height so it scales to its container, and wrap the component with forwardRef to expose the underlying <svg> node.

Pick JavaScript or TypeScript output: the TypeScript variant types props as React.SVGProps<SVGSVGElement> and, with forwardRef enabled, uses forwardRef<SVGSVGElement, React.SVGProps<SVGSVGElement>>. The component is emitted as an exported arrow function (export const Icon = (props) => (...)), with your chosen name and indent, ready to paste into an icon module.

Frequently asked questions

How are SVG attributes converted?
Hyphenated and colon-namespaced attributes are camelCased to their React equivalents: stroke-width to strokeWidth, fill-rule to fillRule, xlink:href to xlinkHref. data-* and aria-* attributes are preserved. Inline styles become style objects.
What does the currentColor option do?
It replaces hard-coded fill and stroke color values (anything other than none) with "currentColor", so the SVG inherits the surrounding text color and can be recolored with plain CSS color on the parent.
Why spread props onto the svg?
Spreading {...props} onto the root <svg> lets callers pass className, width, onClick, aria labels, and any other SVG props to the component. With forwardRef enabled, a ref is also forwarded to the underlying element.
What is the difference between JS and TS output?
TypeScript output types the props as React.SVGProps<SVGSVGElement>, and with forwardRef it uses forwardRef<SVGSVGElement, React.SVGProps<SVGSVGElement>>. JavaScript output omits the type annotations but is otherwise identical.

More tools