How to Use SVG Icons in React: Components, Props and Best Practices
The practical guide to using SVG icons in React, inline vs import, turning SVGs into reusable components, passing size and colour via props, and accessibility.
SVG to React converts a pasted SVG into a clean, production-ready React component with camelCased attributes and props spread through. Choose TypeScript or JS output and optionally add memo, forwardRef or React Native. A live preview and one-click copy are included, free and fully in-browser.
The GigAI SVG to React converter transforms raw SVG markup into an idiomatic React component you can drop straight into a codebase, without the copy-paste-then-fix-the-JSX ritual. It rewrites every DOM attribute to its camelCase JSX form (class → className, stroke-width → strokeWidth, xlink:href → xlinkHref, fill-rule → fillRule and dozens more), spreads a typed props object onto the root so callers can pass size, color, aria-* and event handlers, and gives you real toggles for the choices that actually matter: TypeScript vs plain JavaScript, a custom PascalCase component name, React.memo wrapping, forwardRef for the SVG ref, and a React Native (react-native-svg) target for mobile apps. The generated code renders live in a syntax-highlighted pane beside a checkerboard preview of the actual icon, so you can confirm it still looks right before you copy or download it as a.tsx /.jsx file. Because the conversion runs entirely on your device with the browser's native parser, your artwork (brand marks, unreleased icons, client assets) is never uploaded, stored or logged. It's the fast, private path from a designer's export to a component that compiles.
Last updated
Paste SVG markup into the editor, drop a .svg file anywhere on the workspace, or load a built-in example to see the output instantly.
Name the component, choose TypeScript or JavaScript, and toggle memo, forwardRef or the React Native target. The code regenerates live as you change anything.
Confirm the icon still renders correctly in the preview pane, switch backgrounds or zoom if you need to inspect a thin stroke or a transparent fill.
Copy the JSX to your clipboard or download it as a .tsx / .jsx file named after your component, then drop it into your project.
class becomes className, stroke-width becomes strokeWidth, xlink:href becomes xlinkHref, every hyphenated and namespaced SVG attribute is rewritten to the JSX form React expects, so the component compiles first try.
Flip a single toggle to emit a fully typed .tsx with React.SVGProps<SVGSVGElement>, or a lean .jsx with no annotations. The import lines and prop signatures adjust to match.
The root SVG receives a spread of your props, so callers pass width, height, fill, className, aria-label or onClick without editing the file. Name the component anything, it's sanitised to a valid PascalCase identifier.
Wrap the export in React.memo to skip re-renders, and forwardRef the SVG element so parents can measure or animate it. Both are opt-in and generate correct, ref-typed code.
Switch to react-native-svg output and the DOM tags become Svg, Path, Circle, G and friends with the right imports: the same icon, ready for an Expo or bare React Native app.
A checkerboard preview renders the actual SVG next to the generated JSX, with light/dark backgrounds and zoom, so you catch a broken path or clipped viewBox before it ships.
Pasting raw SVG into a component throws a wall of 'Unknown DOM property' warnings. This does every rename at once, so a designer's export becomes a working component in one click instead of ten edits.
Because props spread onto the root, one generated component covers every size and color you need: pass className for Tailwind, fill for theming, or aria-label for accessibility, no forks required.
The same paste produces a DOM component or a react-native-svg component, so design systems that ship to web and mobile keep a single source of truth for each icon.
Conversion happens locally in your browser. Unreleased logos, client artwork and internal icons never leave your machine. Nothing is uploaded, stored or logged.
From quick one-off fixes to daily workflows, see how people put this tool to use.
Paste the SVG a designer handed off and get a typed, props-spread React component that drops into your icon library and compiles without a single warning.
Generate a DOM component for the web app and a react-native-svg component for the mobile app from the same source, keeping both platforms visually in sync.
Convert each SVG to a memoised, forwardRef component so consumers import only what they use and can attach refs for animation or measurement.
See exactly which attributes React renames and how props flow onto an element, using a real icon instead of a contrived example.
Accepts SVG, and produces JSX and TSX, all processed locally in your browser.
Minify and clean SVG files in your browser with SVGO, strip editor metadata, round coordinates, drop hidden layers and see the exact bytes and percentage saved. Nothing is uploaded.
Aggressively minify SVG online: collapse whitespace, strip comments, metadata and editor namespaces, and squeeze markup to a single line with a live before/after size and % saved. 100% in your browser.
Convert SVG to a data: URI in your browser, URL-encoded or base64, and copy it as a CSS background, an inline <img src>, or the raw URI, with a live size comparison. Nothing is uploaded.
Open, paste or drop an SVG to view it on a checkerboard, light or dark canvas with zoom, live dimensions, a source-code pane and a full element/color report: 100% in your browser, nothing uploaded.
Format, validate and minify JSON in your browser with pinpoint error line + column, jump-to-error, key sorting and live editing: nothing is uploaded.
Decode a data:image/svg+xml URI back into raw SVG in your browser, handles base64 and URL-encoded payloads, with a live preview and one-click.svg download. Nothing is uploaded.
Go deeper on the concepts behind the svg to react.
Hit a snag? Here are quick fixes for the issues people run into most.
The input must be a single well-formed <svg>…</svg> root. Strip any leading XML/doctype declaration or surrounding HTML, and make sure every tag is closed. Running the markup through the SVG Validator first will pinpoint the issue.
If the SVG hard-codes fill or stroke, that color wins over CSS. Set fill="currentColor" (or stroke="currentColor") in the source so the icon inherits the surrounding text color, then re-convert.
Inline style="…" strings and a few exotic attributes can't be auto-converted to React's object form. Move such styling to props or a stylesheet, or replace inline styles with plain presentation attributes before converting.
The native target emits react-native-svg tags (Svg, Path, Circle, G…). Add react-native-svg to your project. A handful of web-only features (filters, some gradients) have limited native support and may need manual tweaks.
Run your SVG through the SVG Optimizer first, fewer nodes and no editor metadata means a smaller, cleaner component.
Turn on forwardRef when a parent needs the element ref, e.g. for GSAP/Framer Motion animation or getBoundingClientRect measurements.
Give the component a descriptive PascalCase name (IconArrowRight, LogoMark). It becomes both the identifier and the download filename.
Leave the props spread on so one component serves every size and color. Pass className, fill or aria-label at the call site instead of editing the file.
Switching to the React Native target? Install react-native-svg in your app, the generated imports assume it's present.
Recent updates and improvements to the svg to react.
Initial release: live SVG→React conversion with camelCased attributes, TypeScript/JavaScript toggle, custom component name, props spread, memo, forwardRef, a React Native target, live preview, and copy/download.
Added undo/redo history, keyboard shortcuts, curated examples, and a shareable-link option that reopens the tool with your SVG pre-loaded.
Improved React Native tag mapping and forwardRef typings, and clearer errors when the input isn't a single well-formed <svg> root.
Every conversion runs entirely in your browser using its native SVG parser. Your markup is never uploaded to any server. Nothing is stored, logged or transmitted, so you can safely convert unreleased logos, client artwork or internal icons. Close the tab and every trace is gone.
Free, private and instant. SVG to React runs right in your browser.