SVG to JSX

Convert SVG markup into JSX you can use in React. Attributes are renamed, style strings become objects, and the SVG can be wrapped in a component that accepts props.

Use the tool

Why this tool exists

Exported icons and illustrations come as SVG files, and pasting them into a React component fails: class must be className, stroke-width must be strokeWidth, and style must be an object. Fixing those by hand in a large file is dull and easy to get wrong.

Paste the SVG and the tool renames attributes, converts namespaced ones like xlink:href, turns inline style into an object, drops the XML declaration and comments, and closes empty tags. With the component option on, it wraps everything in an exported function that spreads props onto the svg element, so you can set size and colour from outside. The conversion is done in your browser, and your artwork is not uploaded.

How to use it

  1. Paste your SVG markup into the input box.
  2. Tick Wrap in component if you want an exported function component, and set its name.
  3. Choose the indent for the generated code.
  4. Copy the JSX into your React project.

Frequently asked questions

What changes are made to the SVG?

class becomes className, hyphenated attributes become camelCase, style strings become objects, namespaced attributes such as xlink:href are converted, and the XML header and comments are removed.

How do I change size or colour?

With the component option, props are spread on the svg element, so you can pass width, height, fill or className when using it. Icons using currentColor follow the text colour.

Does it optimise the SVG?

No. It converts syntax only. To reduce file size first, run the SVG through an optimiser such as the SVG Optimizer tool.

What if my SVG is malformed?

The tool reports a parse error instead of generating code. Look for unclosed tags, mismatched names or unescaped characters such as a bare ampersand in the markup.