Loading SVG to JSX Converter...

SVG to JSX Converter - Convert SVG Icons to React Components

Paste an exported SVG straight into a React file and you will usually get warnings or a broken icon: stroke-width, class and inline style strings are all spelled the HTML way, not the React way. Paste it here instead and you get plain JavaScript JSX that React draws the same way the browser drew the file. Tidy it with the JSX formatter if you like, or go the other way with the JSX to SVG converter.

How to Convert SVG to JSX - Step by Step Guide

1

Paste or Upload SVG Code

Copy the SVG code from Figma, Illustrator, Inkscape or a text editor and paste it into the left editor, or click Upload and pick the .svg file. Icons, logos and full illustrations all work, including gradients, masks and text. Got HTML or Markdown instead? The HTML to JSX converter and Markdown to JSX converter handle those.

<!-- Example SVG code -->
<svg width="24" height="24" viewBox="0 0 24 24">
  <path stroke-width="2" d="M12 2L2 7L12 12" />
</svg>
2

Automatic Conversion to JSX

Half a second after you stop typing, the JSX shows up on the right. Here is the real output for the example above: stroke-width became strokeWidth and viewBox kept its capital B. If the SVG has a mistake, such as a missing closing tag, you get the line and column instead of half-converted code. Moving to TypeScript later? The JSX to TSX converter adds the types.

<svg width="24" height="24" viewBox="0 0 24 24">
  <path strokeWidth="2" d="M12 2L2 7L12 12" />
</svg>
3

SVG Attribute Conversions

Stroke, fill, font and text attributes get the camelCase names React uses, xlink:href becomes xlinkHref and xml:space becomes xmlSpace. Not everything with a dash changes, though: data-* and aria-* attributes keep their dashes because React passes them through as they are, and Inkscape-style names with a colon go into a small spread object. A style="…" attribute becomes a style object; for whole stylesheets, the CSS to JSX converter does the same job.

// Common attribute conversions:
stroke-width → strokeWidth
fill-opacity → fillOpacity
stroke-linecap → strokeLinecap
font-family → fontFamily
xlink:href → xlinkHref
data-name, aria-hidden → unchanged
4

Copy or Download JSX Component

Copy the JSX or download it as icon.jsx. What you get is the <svg> element, so wrap it in a small component like the one below and spread the props onto it to set size, color or click handlers from outside. The JSX validator will double-check the file, and the JSX minifier squeezes it if size matters.

const Icon = (props) => (
  <svg width="24" height="24" viewBox="0 0 24 24" {...props}>
    <path strokeWidth="2" d="M12 2L2 7L12 12" />
  </svg>
);

Frequently Asked Questions

How do I convert SVG to JSX for React?

Paste the SVG into the left editor or upload the .svg file, and the JSX shows up on the right half a second later. class becomes className, stroke-width becomes strokeWidth, style="…" becomes a style object, and the output is plain JavaScript with no type annotations, so it drops straight into a .jsx file in a Vite, Create React App or Next.js JavaScript project. If you want it laid out in your own style afterwards, the JSX formatter will tidy it.

Which attributes get renamed, and which stay as they are?

Only the ones React has its own spelling for: stroke-width → strokeWidth, stroke-linecap → strokeLinecap, fill-opacity → fillOpacity, fill-rule → fillRule, font-family → fontFamily, text-anchor → textAnchor, xlink:href → xlinkHref, xml:space → xmlSpace and so on. Names that already have capitals, like viewBox or preserveAspectRatio, keep them; lower-casing them would stop the icon from scaling. data-* and aria-* attributes keep their dashes, because React passes them through untouched.

Do I get a finished React component?

You get the <svg> element itself, which is usually what you want to paste. To make it reusable, return it from a function and spread the props onto the root: const Icon = (props) => (<svg {...props} …>…</svg>). Then width, className, onClick and the rest can be set wherever the icon is used. Working in TypeScript instead? The SVG to TSX converter gives you output that type-checks in a .tsx file.

Can it handle complex SVG graphics, not just icons?

Yes. Gradients, masks, clip paths, filters, <use> references, text with <tspan> runs, <style> blocks (CDATA included) and <foreignObject> all come through. Spaces inside <text> are kept, and braces or angle brackets in text are escaped so they show up as text instead of breaking the JSX. Numbers in attributes are copied exactly as you wrote them.

What happens to Figma, Illustrator and Inkscape extras?

Figma exports normally convert without anything special. Illustrator files keep their xml:space and enable-background settings. Inkscape and Sodipodi attributes such as inkscape:label are kept in a spread object like {...{ "inkscape:label": "Layer 1" }}, since JSX cannot write a name containing a colon. Editor-only elements such as <sodipodi:namedview> are left out, and a note under the output says so; browsers never draw them anyway.

What if my SVG has a mistake in it?

SVG is XML, so it is read strictly. A missing closing tag, a bare & or an HTML entity like &nbsp; stops the conversion, and you get the line and column plus a short note on what to fix. Event attributes such as onclick="go()" become arrow functions like onClick={() => { go(); }}, and the function they call still has to exist in your own code.

Why inline SVG as JSX instead of using an <img> tag?

Inline SVG picks up currentColor and your CSS, can be animated, and takes props like any other component. The cost is a bigger JavaScript bundle, so it pays off for icons and small graphics more than for detailed illustrations, which are better left as files. To turn JSX back into a standalone .svg, use the JSX to SVG converter.