Boneyard Tools

Convert SVG to JSX for React

Paste raw SVG and get JSX that compiles in React. This tool camel-cases attributes like stroke-width and xlink:href, renames class to className and for to htmlFor, turns an inline style string into a style object, self-closes empty elements, and converts HTML comments to JSX comments. Toggle the component wrapper to get a ready-to-use React component. Everything runs in your browser, so your markup is never uploaded.

How to convert SVG to JSX

  1. Paste your SVG markup into the input box.
  2. Optionally name the component and turn on the component wrapper.
  3. Copy the JSX and paste it straight into your React file.

Examples

Icon attributes to JSX

<path stroke-width="2" fill-rule="evenodd" d="M0 0h24v24H0z"/>
<path strokeWidth="2" fillRule="evenodd" d="M0 0h24v24H0z" />

Frequently asked questions

Why does SVG not work directly in React?

JSX is not HTML. SVG uses hyphenated and namespaced attributes like stroke-width and xlink:href, reserved words like class and for, and inline style strings, all of which JSX rejects. This tool rewrites those into the camelCased names, className, htmlFor and style objects that React expects.

What exactly does it convert?

It camel-cases hyphenated and colon attributes (stroke-width to strokeWidth, xlink:href to xlinkHref), maps class to className and for to htmlFor, converts a style string to a JSX style object with camelCased CSS properties, self-closes empty elements such as path and circle, and turns HTML comments into JSX comments. data-* and aria-* attributes are left as is.

Can it wrap the SVG in a React component?

Yes. Turn on the component wrapper and the output becomes an exported function component that returns the SVG, using the component name you choose. Leave it off to get just the converted JSX to drop into existing markup.

Is my SVG uploaded anywhere?

No. The conversion runs entirely in your browser as you type. Nothing is sent to a server, so private or proprietary artwork stays on your device.

Does it minify or optimize the SVG?

No. It only rewrites the markup so it is valid JSX, leaving your paths, viewBox and structure unchanged. To shrink the file first, optimize the SVG separately, then paste the result here.

Related tools