SVG to React converter

Convert SVG to a React component

Paste an SVG or drop in a file. You get a tidy React component in JSX or TypeScript, with its size and color driven by props.

Output
Colors

SVG

Preview

React component

import type { SVGProps } from "react";

interface BellIconProps extends SVGProps<SVGSVGElement> {
  size?: number | string;
  /** Read by screen readers. Without one, the icon is hidden from them. */
  title?: string;
}

export default function BellIcon({ size = 24, title, ...props }: BellIconProps) {
  return (
    <svg
      xmlns="http://www.w3.org/2000/svg"
      viewBox="0 0 24 24"
      width={size}
      height={size}
      role={title ? "img" : undefined}
      aria-hidden={title ? undefined : true}
      {...props}
    >
      {title ? <title>{title}</title> : null}
      <g
        id="bell"
        fill="none"
        fillRule="evenodd"
        stroke="currentColor"
        strokeWidth="2"
        strokeLinecap="round"
        strokeLinejoin="round"
      >
        <path d="M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9" />
        <path d="M10.3 21a1.94 1.94 0 0 0 3.4 0" />
        <circle cx="18" cy="5" r="3" fill="currentColor" stroke="none" />
      </g>
    </svg>
  );
}
  • Removed 6 things the icon doesn't need: comments, metadata, titles and editor attributes.
  • Turned the icon's color into currentColor, so it takes the text color around it (or a color prop).
  • Free, no sign-up
  • Runs in your browser
  • Your code never leaves your device

How to use it

How to use the SVG to React tool

Free, with no sign-up. Everything happens in your browser.

  1. 01

    Paste or drop your SVG

    Paste the code, open an .svg file or drag one onto the input. Exports from Figma, Sketch, Illustrator and Inkscape all work.

  2. 02

    Pick the output

    TypeScript or JavaScript, and whether colors become currentColor so the icon follows your text color. The name comes from the file, and you can change it.

  3. 03

    Copy or download

    Check the preview and the notes, then copy the component or save it as a .tsx or .jsx file in your icons folder.

Guide

From SVG file to icon component

An SVG straight out of a design tool works in the browser, but not as a React component. It needs its attributes renamed, its leftovers removed and its size and color opened up to props. Here's what the converter does.

Attributes in camelCase

JSX uses JavaScript names for attributes. In SVG that means stroke-width becomes strokeWidth, fill-rule becomes fillRule, stop-color becomes stopColor and xlink:href becomes xlinkHref. class becomes className, as in any React code.

viewBox already is camelCase, and data-* and aria-* attributes keep their hyphens.

SVG
<path stroke-width="2" stroke-linecap="round"
      fill-rule="evenodd" d="M5 12h14" />
JSX
<path strokeWidth="2" strokeLinecap="round"
      fillRule="evenodd" d="M5 12h14" />

Cleaning up editor leftovers

Design tools add things a component doesn't need: the <?xml ?> declaration, comments, <metadata>, <title> and <desc> elements, version attributes, ids on the root and editor namespaces such as sketch:, inkscape: and sodipodi:.

The converter removes them, along with xmlns:xlink when nothing uses it and empty <defs>. The drawing itself, its paths, groups, gradients and masks, is left exactly as it was.

Size props, with the viewBox doing the scaling

A fixed width and height make an icon one size forever. The converter moves them into props: a size prop for square icons (defaulting to the original size), or width and height props for other artwork.

The viewBox stays, so the drawing scales cleanly at any size. If your SVG had a width and height but no viewBox, one is added from them.

Use it
<BellIcon />
<BellIcon size={16} />
<BellIcon size="1.5em" className="text-teal-600" />

Colors that follow your text

With Colors set to currentColor, each hard-coded fill and stroke becomes currentColor. The icon then takes the color of the text around it, so a Tailwind class like text-red-500, a color prop or a parent's CSS can change it. none, gradients (url(#…)) and CSS variables are left alone.

Multicolor illustrations and logos should keep their colors, so switch Colors to Keep for those.

SVG
<path stroke="#0F172A" fill="none" … />
JSX
<path stroke="currentColor" fill="none" … />

Accessible by default

Most icons sit next to a text label, so the component hides them from screen readers with aria-hidden. Pass a title when the icon stands alone, like an icon-only button, and the component renders a <title> and role="img" instead.

Any other prop, such as className, onClick or style, is passed straight through to the <svg>.

Icon-only button
<button type="button">
  <BellIcon title="Notifications" />
</button>

What it handles

Built for real-world code

The details that usually need fixing by hand, done for you.

  • TypeScript or JavaScript

    TSX output comes with a typed props interface that extends SVGProps<SVGSVGElement>, so every SVG prop is checked and autocompleted.

  • Works with any exporter

    Figma, Sketch, Illustrator and Inkscape exports, icon sets and hand-written SVG are all handled, including namespaced editor markup.

  • Live preview

    See the cleaned icon at 16, 24 and 40 pixels on dark and light backgrounds before you copy it.

  • Private by design

    Files you open or drop are read in your browser. Nothing is uploaded, stored or logged.

Screenshot to Code

Need the whole page, not just its icons?

Upload a screenshot of any page or mockup and get a complete React and Tailwind version, split into components, with a live preview you can refine by chat.

FAQ

Questions about SVG to React

Something else on your mind? Send us a message.

Yes. It's free with no sign-up and no limits, and it runs entirely in your browser.

More free tools

Keep going

More converters for HTML, React and Tailwind.