SVG to React Component
Paste an SVG to get a ready-to-use React component. Attributes are converted, editor clutter is removed, and props pass through to the <svg>.
Last updated
SVG
WifiIcon.tsx
Convertedimport type { SVGProps } from "react";
export default function WifiIcon(props: SVGProps<SVGSVGElement>) {
return (
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...props}>
<path d="M5 12.55a11 11 0 0 1 14.08 0" />
<path d="M1.42 9a16 16 0 0 1 21.16 0" />
<path d="M8.53 16.11a6 6 0 0 1 6.95 0" />
<circle cx="12" cy="20" r="1" fill="currentColor" />
</svg>
);
}
Hard-coded fill and stroke colours were replaced with currentColor, so the icon inherits the text colour.
Keyboard shortcuts:Ctrl ↵Copy outputCtrl SDownloadCtrl KSearch tools
How to use the SVG to React Component
Paste the SVG
Open the .svg file in a text editor or export it from your design tool, and paste the code.
Name the component
Give it a PascalCase name such as WifiIcon.
Pick options
TypeScript or JavaScript, currentColor for theming, and whether to drop width and height.
Save the file
Download WifiIcon.tsx (or .jsx) and import it like any component.
Features
- Generates a complete component that spreads props onto the <svg>
- TypeScript output typed with SVGProps<SVGSVGElement>, or plain JavaScript
- Converts attributes to JSX: stroke-width → strokeWidth, class → className, xlink:href → xlinkHref
- currentColor option replaces hard-coded fill and stroke colours so icons follow the text colour
- Optionally removes width and height so the icon can be sized with CSS
- Removes XML declarations, comments, <metadata> and Inkscape / Sketch attributes
- Pretty-prints the markup, even from minified SVGs
Privacy
Your SVG is processed by JavaScript in your browser tab. Nothing is uploaded or stored, and the page's security policy blocks it from sending data to any other site.
Examples
An icon with currentColor
The stroke colour becomes currentColor, so the icon follows the text colour.
SVG
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="#0f172a" stroke-width="2" stroke-linecap="round"><path d="M5 12.55a11 11 0 0 1 14.08 0"/><path d="M8.53 16.11a6 6 0 0 1 6.95 0"/><circle cx="12" cy="20" r="1"/></svg>WifiIcon.tsx
import type { SVGProps } from "react"; export default function WifiIcon(props: SVGProps<SVGSVGElement>) { return ( <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" {...props}> <path d="M5 12.55a11 11 0 0 1 14.08 0" /> <path d="M8.53 16.11a6 6 0 0 1 6.95 0" /> <circle cx="12" cy="20" r="1" /> </svg> ); }Clean up an Inkscape export
Editor metadata is removed and the style string becomes an object. JavaScript output.
SVG
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <svg xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" sodipodi:docname="bolt.svg" inkscape:version="1.3"> <sodipodi:namedview id="base" /> <path style="fill:#f59e0b;stroke:none" d="M13 2 3 14h9l-1 8 10-12h-9z" /> </svg>BoltIcon.jsx
export default function BoltIcon(props) { return ( <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" {...props}> <path style={{ fill: "#f59e0b", stroke: "none" }} d="M13 2 3 14h9l-1 8 10-12h-9z" /> </svg> ); }A multi-colour logo
currentColor is off, so the brand colours stay. Width and height are left to CSS.
SVG
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><rect width="32" height="32" rx="7" fill="#6366f1"/><circle cx="16" cy="16" r="6" fill="#ffffff"/></svg>Logo.tsx
import type { SVGProps } from "react"; export default function Logo(props: SVGProps<SVGSVGElement>) { return ( <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" {...props}> <rect width="32" height="32" rx="7" fill="#6366f1" /> <circle cx="16" cy="16" r="6" fill="#ffffff" /> </svg> ); }
Understanding SVG icons in React
Why turn SVGs into components?
An inline SVG component can be styled with CSS (colour, size, hover effects), needs no extra network request, and accepts props like className, aria-label and onClick. Using <img src="icon.svg"> is simpler, but you can't change the icon's colour from your CSS.
import WifiIcon from "./WifiIcon";
<WifiIcon className="size-5 text-sky-500" aria-hidden="true" />Theming with currentColor
currentColor makes a fill or stroke use the element's CSS color. With the currentColor option on, the icon inherits the colour of the text around it, so one component works on light and dark backgrounds and in hover states. Leave it off for multi-colour illustrations and logos.
Accessibility
- Decorative icons next to text: pass
aria-hidden="true". - Icons that carry meaning on their own: pass
role="img"and anaria-label. - Icon-only buttons: put the label on the
<button>, not the SVG.
Frequently asked questions
How do I change the icon's colour?
Turn on currentColor, then set the CSS color of the icon or its parent, for example className="text-red-500". Without currentColor, the colours written in the SVG are used.
How do I resize the component?
Pass width and height props, or turn on Remove width / height and size it with CSS. The viewBox keeps the proportions either way.
Is this the same as SVGR?
It does the same core job as SVGR's default template — a component that spreads props onto the svg — in your browser, without installing anything. SVGR adds build-time integration and SVGO optimisation.
Why were some attributes removed?
Design tools add metadata such as inkscape: and sodipodi: attributes and <metadata> elements. They don't affect rendering and aren't valid in JSX, so they're removed. The notes list everything that changed.
Does it optimise the SVG paths?
No. Paths are kept exactly as they are. Run the file through an optimiser such as SVGO first if you want smaller paths.