FormatterHQ

SVG to JSX / React Component

Paste an SVG and get a ready-to-use React component with valid JSX attributes, style objects, props spreading and optional TypeScript types.

Input XML
Output JSX
Ready.

How to use the SVG to JSX / React Component

  1. Paste SVG markup into the input editor or upload an .svg file.
  2. Set the Component name (it is converted to PascalCase).
  3. Choose TypeScript, how to treat width / height and whether to wrap in React.memo.
  4. Copy or download the component and import it in your app.

Convert SVG to JSX for React

SVG markup is almost valid JSX — almost. React requires className instead of class, camelCase attributes such as strokeWidth, and style as a JavaScript object. Pasting an exported icon into a component therefore produces errors and warnings. This SVG to JSX converter rewrites the markup correctly and wraps it in a component you can import anywhere.

Example

// input
<svg class="icon" stroke-width="2" style="fill-opacity:0.2">…</svg>

// output
import * as React from 'react';

const HeartIcon = (props) => (
  <svg className="icon" strokeWidth="2" style={{ fillOpacity: 0.2 }} {...props}>
    …
  </svg>
);

export default HeartIcon;

What gets converted

  • Attributes: hyphenated names become camelCase (stroke-linecap → strokeLinecap, fill-rule → fillRule); class → className; namespaced ones like xlink:href → xlinkHref. data-* and aria-* stay as they are.
  • Inline styles: style="fill-opacity:0.2;fill:currentColor" becomes an object, with numeric values kept as numbers.
  • Clean-up: the XML declaration, DOCTYPE, comments and Inkscape/Sodipodi editor attributes are dropped.
  • Text: braces in text nodes are escaped so JSX does not treat them as expressions.
  • Props: {...props} is spread onto the root <svg>, so you can pass className, aria-label or event handlers.

Options

  • TypeScript: adds SVGProps<SVGSVGElement> typing — save the result as .tsx.
  • width / height: keep the original values, remove them so CSS controls the size, or set them to 1em so the icon scales with the surrounding font size like an icon font.
  • React.memo: wraps the component to skip re-renders when props do not change.

Tips for icon components

Replace hard-coded colours with currentColor so icons inherit the text colour, and run the SVG through the SVG optimizer first for smaller components. For React Native, use SVG to React Native, which outputs react-native-svg elements. Converting HTML rather than SVG? The HTML to JSX converter handles that.

Building an icon library

Convert each icon once, name the components consistently (ArrowLeftIcon, CheckIcon…) and export them from an index.js file. Because each icon is a separate component, bundlers can tree-shake unused ones. With dimensions set to 1em and colours set to currentColor, the icons size and colour themselves from the surrounding text, so a button only needs a font size and colour for text and icon to match.

Inline SVG versus img tags

Using an SVG as a component (inline SVG) lets you style parts of it with CSS, animate paths, change colours on hover and add accessible titles. Loading it with an <img> tag is simpler and cacheable but the graphic cannot be styled from outside. For UI icons that follow theme colours and states, components are usually the better choice; for large illustrations that never change, an image file keeps your JavaScript bundle smaller.

Accessibility

Decorative icons should be hidden from screen readers with aria-hidden="true", which you can pass as a prop. Meaningful icons need a label: pass aria-label and role="img", or keep a <title> element inside the SVG.

Privacy

The tool runs entirely in your browser. Nothing you type or paste is sent to our servers.

Frequently asked questions

Why does React complain about class and stroke-width?
JSX uses DOM property names: class must be className and hyphenated SVG attributes must be camelCase (strokeWidth). The converter applies these renames automatically.
How do I change the icon color from outside?
Use fill="currentColor" or stroke="currentColor" in the SVG, then set the CSS color on the component or its parent.
Does it work with Next.js and Vite?
Yes. The output is a plain React function component with no dependencies, so it works in any React setup.
Can I get TypeScript output?
Yes. Tick TypeScript to type the props as SVGProps.

Last updated September 26, 2026

Related tools

HTML to JSX Converter Convert HTML markup to valid JSX for React: className, htmlFor, style objects, self-closing tags and comments handled automatically. SVG to Base64 Convert SVG markup or an .svg file to a Base64 data URI for CSS backgrounds, img tags and JSON. SVG to CSS Data URI Encode SVG as an optimized URL-encoded data URI for CSS background-image or mask, with a Base64 version for comparison. SVG to JPG Converter Convert SVG graphics to JPG images with a chosen background colour, scale and quality — directly in your browser. SVG to PNG Converter Convert SVG to PNG at any size or scale (2×, 4×…) with a transparent or solid background. Paste code or upload an .svg file. SVG to React Native Convert SVG files into react-native-svg components (Svg, Path, G, Circle…) ready to paste into your React Native app. WEBP to JPG Converter Convert WEBP images to JPG online for free. Fast, private, in-browser conversion with preview and size comparison. WEBP to PNG Converter Convert WEBP images to PNG online for free. Fast, private, in-browser conversion with preview and size comparison. BMP to JPG Converter Convert BMP images to JPG online for free. Fast, private, in-browser conversion with preview and size comparison. BMP to PNG Converter Convert BMP images to PNG online for free. Fast, private, in-browser conversion with preview and size comparison. EXIF Remover (Strip Photo Metadata) Remove EXIF, GPS location, XMP and other metadata from photos before sharing. JPEG and PNG are cleaned losslessly, in your browser. EXIF Viewer Read EXIF, GPS, XMP, IPTC and ICC metadata from photos — camera, lens, exposure, date and location — without uploading the file.