Skip to content
ToolPlankDEV
Image & SVG Tools
100% In-Browser Execution

Updated:

JSX to SVG Converter

Convert JSX to SVG in your browser. Paste React SVG markup or a whole component and get a plain SVG file, with strokeWidth back to stroke-width, className to class and style objects to style strings. Dynamic values are listed. Nothing is uploaded.

Options:

JSX

Input
0 chars · 0 lines

SVG

Ready
Processing in browser...
0 chars · 0 linesUpdates as you type

Preview of the SVG result

A preview of the SVG appears here. Scripts and event handlers are never run.

What changed

Renamed attributes and skipped dynamic values are listed here.

Processed on your device. Your text is not sent to our servers.

More free tools you may need next.

Quick Guide

How to use JSX to SVG

Simple step-by-step instructions to get the exact output you need.

  1. 01

    Paste the JSX

    Paste JSX that contains an <svg> element, or a whole React component file. Anything before the <svg> tag, such as imports, is ignored.

  2. 02

    Check the result and preview

    The SVG appears in the output box and as a picture under the editors. The What changed box lists renamed attributes and any dynamic values that were skipped.

  3. 03

    Copy or download

    Press Copy, or Download to save image.svg.

Convert JSX to SVG

An icon written for React is not a valid .svg file. Browsers and design tools want class instead of className, stroke-width instead of strokeWidth, and style as a CSS string. This JSX to SVG converter changes them back. The Sample component:

jsx
export const CheckIcon = (props) => (
  <svg xmlns="http://www.w3.org/2000/svg" className="icon" viewBox="0 0 24 24" {...props}>
    <circle cx={12} cy={12} r={9} fill="none" stroke="currentColor" strokeWidth={2} />
    <path
      d="M8 12.5l2.5 2.5L16 9.5"
      fill="none"
      stroke="currentColor"
      strokeWidth="2"
      strokeLinecap="round"
      style={{ opacity: 0.9 }}
    />
  </svg>
);

becomes:

xml
<svg xmlns="http://www.w3.org/2000/svg" class="icon" viewBox="0 0 24 24">
  <circle cx="12" cy="12" r="9" fill="none" stroke="currentColor" stroke-width="2" />
  <path
    d="M8 12.5l2.5 2.5L16 9.5"
    fill="none"
    stroke="currentColor"
    stroke-width="2"
    stroke-linecap="round"
    style="opacity: 0.9"
  />
</svg>

What Is Converted

  • className to class, htmlFor to for, tabIndex to tabindex.
  • camelCase attributes to their SVG names: strokeWidth to stroke-width, fillRule to fill-rule, xlinkHref to xlink:href.
  • SVG attributes that really are camelCase, such as viewBox, gradientUnits and stdDeviation, are kept.
  • Fixed values in braces: {12} becomes "12", {"M0 0"} becomes "M0 0", {false} becomes "false".
  • Style objects to CSS: {{ strokeWidth: 2, fontSize: 12 }} becomes stroke-width: 2; font-size: 12px, adding px where React would.
  • {...props}, key, ref, event handlers such as onClick and JSX comments are removed.

With Add xmlns on, the SVG namespace is added when it is missing, and the xlink namespace when xlink:href is used, so the file opens on its own.

Dynamic Values Are Listed, Not Guessed

A value that comes from a variable or a calculation has no fixed value in the code, so it cannot be written into a file. The tool leaves it out and lists it. For example:

jsx
<svg viewBox="0 0 24 24">
  <path d="M4 12h16" stroke={color} strokeWidth={size / 8} />
</svg>

gives:

xml
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
  <path d="M4 12h16" />
</svg>

and the What changed box shows stroke={color} and strokeWidth={size / 8} under Skipped dynamic values. Replace them with real values in the JSX, or add the attributes to the SVG by hand.

TSX, Typed Props and Conditional Parts

TypeScript does not get in the way. The tool looks for the first <svg> tag, so type annotations, props interfaces and the arrow function around it are skipped. Only the <svg> element is converted. Take this icon:

tsx
const Icon = ({ size }: Props) => (
  <svg width={24} height={24} viewBox="0 0 24 24">
    <g clipPath="url(#a)">
      <path d="M0 0h24" fillRule="evenodd" />
    </g>
    <defs>
      <clipPath id="a"><rect width="24" height="24" /></clipPath>
    </defs>
  </svg>
);

The result keeps <clipPath> as a tag name and viewBox as it is, but writes the attributes as clip-path and fill-rule. Tag names and attribute names are treated differently on purpose, because SVG itself uses a camelCase tag called clipPath and a hyphenated attribute called clip-path.

Parts that depend on code, such as {cond && <path />} or text like {name}, cannot be turned into a fixed file. They are dropped and shown under Skipped dynamic values, so you see exactly what to fill in by hand. If the input holds more than one <svg>, only the first is converted.

Common Problems

  • The output has no colors: the JSX used fill={color} or stroke={color}. Put a real value such as "#1a73e8" or "currentColor" in the JSX first.
  • The icon looks tiny or huge: the JSX had width={size}. Set width and height, or keep only viewBox so the SVG scales to its container.
  • Nothing happens and you see No <svg> element found: the pasted code has no <svg> tag. Check that you copied the component that holds the markup, not only its wrapper.
  • The file works in a browser but a design tool rejects it: turn on Add xmlns, which adds the namespace attribute many tools expect.

Go back to React with SVG to JSX or the swap button. Turn the SVG into an image with SVG to PNG, or into an Android vector drawable with SVG to XML.

Privacy

Your code is converted in your browser and never uploaded. See the Privacy Policy.

Frequently Asked Questions

Technical Q&A for JSX to SVG

Common questions about edge cases, character encoding, and privacy guarantees.

Paste the JSX or the component above. The SVG appears right away; press Copy or Download.

Yes. The tool finds the first <svg> tag and converts that element. Imports, types and the component wrapper are ignored.

Values that come from variables are left out and listed under Skipped dynamic values, because the code does not say what they are.

React adds px to plain numbers for most style properties, so fontSize: 12 renders as font-size: 12px. Unitless ones such as opacity and strokeWidth stay plain, matching what React does.

No. react-native-svg uses components such as <Path> and <Circle>; this tool expects normal lowercase SVG tags.

Yes. Type annotations and prop interfaces outside the <svg> tag are ignored. You can also upload a .jsx or .tsx file instead of pasting.

Only the first <svg> element is converted. Paste the other icon on its own to convert it too.

In SVG, the tag <clipPath> really is camelCase, while the attribute is clip-path. The tool renames the attribute and leaves real SVG tag names such as clipPath and linearGradient unchanged.

No. The conversion runs in your browser, so your component code stays on your device.