SVG to React Converter

Turn SVG markup into a React component: attributes become JSX, props pass through, size and color can follow CSS, in TypeScript or JavaScript.

Processed on your device. Files are not uploaded

How to turn an SVG into a React component

  1. Paste your SVG

    Paste or type your SVG into the box, or press Try an example.

  2. Set the options

    TypeScript, props, size and color handling.

  3. Copy the component

    Save it as a .tsx or .jsx file in your project.

Worked example

This is what SVG to React Converter gives for its own sample values. Open the tool above and change anything to try your own.

SVG

<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="#0f766e" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon">
  <path d="M3 12l9-9 9 9"/>
  <path d="M5 10v10h14V10"/>
</svg>
Component name
HomeIcon
TypeScript
Yes
Pass props through ({...props})
Yes
Remove width and height (size it with CSS)
Yes
Use currentColor for fill and stroke
Yes
Wrap in React.memo
No

HomeIcon.tsx

import type { SVGProps } from "react";

export default function HomeIcon(props: SVGProps<SVGSVGElement>) {
  return (
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className="icon" {...props}>
      <path d="M3 12l9-9 9 9" />
      <path d="M5 10v10h14V10" />
    </svg>
  );
}

When to use SVG to React Converter

A designer exported icons as SVG files and you want them as React components in your codebase.

An inline SVG pasted into JSX throws errors about class, style or hyphenated attributes.

Tips for a better SVG to React Converter result

Name the component after what the icon means, such as TrashIcon, rather than the file name it was exported with.

Turn on currentColor for single-color icons, but leave it off for illustrations that need their own colors.

SVG to React Converter: limits and what to check

Gradients and filters use ids that must be unique on the page, so two copies of the same icon can clash.

Embedded raster images and fonts inside the SVG are kept, which can make the component large.

About SVG to React Converter

Turn an icon or illustration into a React component you can style and size like text. Attributes become their JSX names (class to className, stroke-width to strokeWidth), editor junk from Inkscape and Illustrator is removed, and props such as className and onClick pass through to the svg element.

FAQs

Why remove width and height?

Then the icon sizes with CSS, for example className="h-5 w-5", instead of being stuck at its original size.

What does currentColor do?

Fill and stroke follow the CSS color of the parent, so one icon works in any color and in dark mode.

Is the SVG made smaller?

Comments and editor metadata go. For more savings, run it through SVG Minifier first.

Related tools