Skip to main content
TOP free online tools Your Workbench
English

SVG to React JSX / TSX Converter

Sanitize SVG markup against XSS and convert hyphenated attributes and inline styles into clean React JSX or TypeScript TSX components locally.

Local browser processing — zero server uploads
XSS-sanitized automatically
3 elements · 8 attrs converted
Sanitized SVG preview
Live Sanitized Preview
Rendered via isolated data URI after stripping scripts, event handlers, and unsafe URLs.

How to Use

  1. Paste raw SVG code into the left editor or upload a local .svg file from your computer.
  2. Select TSX Component, JSX Component, or Raw JSX mode and customize the component name if desired.
  3. Verify the live sanitized preview, then copy the JSX code or download the .tsx/.jsx component file.

What is SVG to React JSX / TSX Converter?

The SVG to React JSX / TSX Converter turns exported vector markup from Figma, Illustrator, or icon sets into valid, ready-to-paste React components. It automatically fixes JSX syntax incompatibilities—such as class, for, hyphenated presentation attributes, colon namespaces, and inline CSS strings—while sanitizing untrusted SVG code.

How It Works

First, the converter runs the project's sanitizeSvg XSS guard to strip scripts, event attributes, and dangerous URLs. Next, a pure TypeScript attribute and style parser camelCases SVG properties, preserves aria-* and data-* accessibility attributes, converts CSS style declarations into JSX object literals, and optionally wraps the output in a typed TypeScript or JavaScript component.

Common Use Cases

  • Converting designer-exported Figma or Heroicons SVGs into typed React TSX icon components
  • Transforming inline style strings into React style={{ ... }} objects without manual editing
  • Safely previewing and cleaning third-party SVG assets to strip hidden scripts or event handlers
  • Generating raw JSX snippets when embedding inline SVG graphics inside existing React templates
Technical Details

Runs entirely client-side with zero external dependencies. Integrates sanitizeSvg XSS sanitization, preserves viewBox and aria-*/data-* attributes, converts CSS declarations to camelCase React style objects, supports SVGProps<SVGSVGElement> TypeScript wrappers, and renders previews via isolated data:image/svg+xml image URIs.

FAQ

Why must SVG attributes be camelCased for React JSX?

React JSX compiles attributes to JavaScript properties, so hyphenated or namespaced attributes like stroke-width, fill-rule, clip-path, class, and xmlns:xlink must become strokeWidth, fillRule, clipPath, className, and xmlnsXlink (while aria-* and data-* stay hyphenated).

How does this tool protect against malicious SVG payloads?

Every input is passed through the built-in sanitizeSvg guard first, stripping <script>, <foreignObject>, inline on* event handlers, and javascript:/data:text/html URIs before JSX conversion and live preview rendering.

Can I generate TypeScript components with SVGProps?

Yes. Select TSX Component mode to emit import type { SVGProps } from 'react' with typed props: SVGProps<SVGSVGElement> and {...props} spreading on the root <svg> element.