Code converters

SVG to JSX Converter

Paste SVG or drop files and get clean, typed React or React Native components, with editor cruft removed, styles inlined and paths optimized.

  • Free foreverNo trial, no paywall, no usage limits.
  • No sign-upOpen the page and start. We never ask for an email to use a tool.
  • PrivateEverything runs in your browser. Your input is never uploaded or stored on our servers.
  • Works offlineOnce the page has loaded, the tool keeps working without a connection.
Typed props with SVGProps<SVGSVGElement> (or SvgProps for React Native). Save as .tsx.Plain JSX with no type annotations. Save as .jsx.
export function Icon: better auto-imports and refactoring, and several icons can share one file.export default Icon: one icon per file, imported under any name.
Keep uses the SVG's own width and height. 1em makes the icon follow the surrounding font size. Size prop adds a size prop. Remove lets CSS decide. A viewBox is added when needed so the icon scales.
Decorative adds aria-hidden so screen readers skip icons next to visible text. Title prop adds an optional title that gives the icon an accessible name (role img plus aria-labelledby).
Replaces fill and stroke colors with currentColor, so the icon takes the CSS text color (Tailwind text-* classes, link color, hover states).
Adds {...props} last on the root <svg>, so className, onClick, aria-label or a different width can be passed in and override the defaults.
Wraps the component in forwardRef for React 18 and older. In React 19, ref is a normal prop, so spreading props already forwards it.
Wraps the component in React.memo so it skips re-rendering when its props have not changed. Useful for large illustrations in busy lists.
Applies <style> rules (like Illustrator's .st0 classes) to each element and turns them into attributes, so the component ships no global CSS that could clash with other icons.
Drops ids nothing points to (layer names like Layer_1). Ids used by gradients, clip paths, masks or <use> are kept.
Prefixes every id and reference with the component name, so two icons on one page cannot steal each other's gradients or clip paths.
Rounds numbers, compacts path data, removes empty groups and default values. Only changes that cannot alter the rendering.
Decimal places kept in coordinates. 2 or 3 is invisible on icons; use more for large illustrations or tiny viewBoxes.

SVG input

Paste markup from Figma, Illustrator, Inkscape or Sketch, or drop several .svg files: each one becomes its own component.
Clear all

Output

The component updates as you type or change options. Pick React, React Native (react-native-svg) or the cleaned SVG itself.
CopyDownload icon.tsx
A React DOM component (Next.js, Vite, Remix…).Uses react-native-svg components: Svg, Path, G… Install react-native-svg in your app.The cleaned, optimized SVG markup, for <img>, CSS backgrounds or a sprite.
Paste SVG markup or drop .svg files. Everything runs in your browser.

Preview

Both previews render the sanitized markup as an image, where SVG scripts can never run. Compare them to confirm the optimizer changed nothing visible.
Shows transparent areas, so you can see the icon's true shape.Preview on white, like a light-theme page.Preview on near-black, to catch icons that vanish in dark mode.
Preview color: what currentColor resolves to (the CSS color of the parent element).
OriginalYour input after the security pass (scripts, event handlers and unsafe links removed), before any cleanup.
Paste an SVG to preview it
ResultThe cleaned SVG your component renders. It should look identical to the original.
Paste an SVG to preview it

Want a site designed with this level of care? Talk to our team

Quick answer

To convert SVG to JSX, rename attributes to their React names (class becomes className, stroke-width becomes strokeWidth, xlink:href becomes xlinkHref), turn style strings into objects, and wrap the markup in a component that spreads props onto the root svg. Playxoft's free SVG to JSX Converter does all of that in the browser, strips scripts and editor metadata, optimizes paths and outputs TypeScript, JavaScript or React Native components.

  • React and React Native
  • TypeScript or JavaScript
  • currentColor and size props
  • Script and handler removal
  • Path optimizer
  • Multi-file batch
  • Before and after preview

How to use the SVG to JSX Converter

  1. 1Paste SVG markup into SVG input, drop one or more .svg files on it, or click Load example.
  2. 2Choose TypeScript or JavaScript, and a Named export or Default export.
  3. 3Set Size and Accessibility, and switch on currentColor, forwardRef or memo if your icon system uses them.
  4. 4Pick the React, React Native or SVG tab, and compare Original with Result in the preview to confirm nothing changed visually.
  5. 5Copy or download the component. With several files, use Copy all or download every component as one module.

Why do SVG attributes change in JSX?

JSX looks like markup but compiles to JavaScript function calls, and each attribute becomes a property on a props object. That is why a few SVG attributes must be renamed before React accepts them:

In SVGIn JSXWhy
class="icon"className="icon"class is a reserved word in JavaScript
stroke-width="2"strokeWidth="2"React names multi-word props in camelCase
fill-rule="evenodd"fillRule="evenodd"The same rule covers every hyphenated presentation attribute
xlink:href="#a"xlinkHref="#a"JSX compilers reject namespaced names by default
xml:space="preserve"xmlSpace="preserve"Same namespace rule
style="fill:red;stroke-width:2"style={{ fill: "red", strokeWidth: "2" }}React styles are objects with camelCase keys
aria-hidden, data-idunchangedReact passes aria-* and data-* through as written
viewBox, gradientUnitsunchangedThese are already camelCase in SVG

Pasting raw SVG into a component usually "works" until it hits one of these: React logs an invalid DOM property warning for stroke-width, and Babel or SWC stop with a namespace error on xlink:href. Note that xlink:href is legacy SVG 1.1 syntax; plain href works in every current browser.

Inline SVG, img or sprite: which should I use?

How you ship an icon matters more than how small its file is:

MethodColor with CSSCached as a fileAdds to your JS bundleBest for
Inline component (this tool)Yes, via currentColorNoYesIcons that change color, size or animate
<img src="icon.svg">NoYesNoLogos and illustrations
Sprite: <use href="/sprite.svg#icon">Yes, via currentColorYesNoLarge icon sets reused across many pages
CSS mask-imageYes, through background-colorYesNoDecorative icons in CSS

Inline components are the most flexible: props, hover states, dark mode and accessibility all just work. The trade-off is that every icon's path data lives in your JavaScript and in every server-rendered page that uses it. For a few dozen icons that is negligible; for hundreds, a sprite sheet referenced with <use> keeps HTML and bundles small. External <use> references must be same-origin.

What does SVG optimization remove, and what is safe?

Design tools export far more than the drawing. A typical Illustrator or Inkscape file carries an XML prolog, generator comments, <metadata>, sodipodi:namedview, layer ids like Layer_1 and coordinates with four decimals. None of it affects rendering, and this converter removes it every time.

The optional optimizer goes further, and only does what cannot change the picture:

  • Rounds numbers. In a 24-unit viewBox, two or three decimals are far below one rendered pixel, so M12.0001,2.2500 becomes M12 2.25.
  • Compacts path data with a real path parser, so arc flags and run-together numbers like 1.5.5 (1.5, then .5) survive.
  • Drops empty groups and defs, and unwraps groups that have no attributes.
  • Removes default values such as stroke-miterlimit="4", but only where no ancestor sets a different value, and never inside <defs> or <symbol>, whose content inherits from where it is used.

What is not safe: rounding a tiny viewBox (such as 0 0 1 1) to two decimals, deleting ids that CSS or scripts target, and deleting the viewBox, which stops an icon from scaling. Some older optimizer presets removed the viewBox by default, so check yours. For build pipelines, SVGO is the standard optimizer and SVGR (via @svgr/webpack or vite-plugin-svgr) turns imported .svg files into React components at build time; this page is for one-off conversions and quick checks.

How do I make an SVG icon accessible?

It depends on what the icon does. Most icons sit next to visible text and are decorative, so hide them from screen readers:

<button>
  <TrashIcon aria-hidden="true" />
  Delete
</button>

An icon that carries meaning on its own, such as a status badge, needs an accessible name. Give the svg role="img" and either an aria-label or a <title> referenced with aria-labelledby. The Title prop option generates exactly that, with an id from React's useId so several icons on a page never share one:

<WarningIcon title="Payment failed" />

For icon-only buttons, put the label on the button (aria-label="Delete") and keep the icon hidden. The rule behind all of this is WCAG 1.1.1 Non-text Content.

How is a React Native SVG component different?

React Native has no DOM, so SVG comes from the react-native-svg library, whose elements are imported components: Svg, Path, G, Circle, LinearGradient and so on. The React Native tab handles the differences for you:

  • Element names are capitalized and imported from react-native-svg.
  • There is no CSS, so <style> blocks and className do nothing. Styles must become props (fill, strokeWidth), which is why Inline styles matters here.
  • Sizes are numbers in density-independent pixels; 1em does not exist, so it becomes a number.
  • currentColor works and resolves to the color prop on Svg.
  • Filter support in react-native-svg is recent and covers only some primitives, so check the library's docs before relying on one.

If you import many .svg files directly, react-native-svg-transformer lets Metro do this conversion at build time.

Frequently asked questions

No. In React 19, ref is a regular prop for function components, so a component that spreads its props onto the root svg already forwards the ref. Turn on forwardRef only if the component must also work in React 18 or older.
currentColor makes a fill or stroke follow the CSS color of the element, so one icon matches link color, hover states and dark mode without editing its markup. It suits single-color icons; multicolor illustrations would lose their palette, which is why the converter warns when several colors are merged.
A style element inside inline SVG is global: its rules apply to the whole page. Illustrator names classes st0 and cls-1 in every export, so two icons on the same page restyle each other. Inlining the rules as attributes removes the clash, and React Native ignores style blocks entirely.
xlink:href is the SVG 1.1 way to point at another element, for example in use or a gradient reference. SVG 2 replaced it with plain href, which every current browser supports. In JSX the old form must be written xlinkHref.
Yes. Drop or open multiple .svg files, or paste several svg elements one after another. Each becomes its own component named after its file, and you can copy them all or download them as a single module.
Before anything renders, the converter removes scripts, event handlers such as onload, javascript: links, CSS imports and external url() references, foreignObject, embedded frames and any element that is not standard SVG, so nothing but SVG tags reaches your JSX. The preview draws the result as an image, where scripts cannot run. Still review third-party SVGs before you ship them.
No. Parsing, sanitizing, optimizing and code generation all run in your browser. Files you drop are read locally, and nothing you paste is stored or sent anywhere.

Last updated by the Playxoft engineering team.

From the designers who built this tool

Want your site to look this polished?

Consistent color, crisp typography and fast pages are what make a site feel premium. We build accessible, high-converting websites with design systems that stay consistent everywhere. Send us your site and we will share honest recommendations, free.

More free tools

See all tools

SQL Formatter

Beautify or minify SQL in 12 dialects, with keyword case, indent and line:column errors.

Open tool

cURL to Python Converter

New

Convert cURL commands into Python requests or httpx code with params, json, files and auth.

Open tool

cURL to Fetch Converter

New

Turn any cURL command into JavaScript fetch() code with headers, JSON, forms and auth.

Open tool

cURL to Axios Converter

New

Convert cURL commands into an Axios request config with params, data, auth and timeouts.

Open tool

SQL to Prisma Converter

Turn SQL DDL into a schema.prisma with native types, relations and enums.

Open tool

SQL to Drizzle Converter

Turn SQL DDL into a typed Drizzle schema.ts with indexes, enums and relations().

Open tool