SVG to TSX Converter - Convert SVG to TypeScript React TSX Components Online
Paste SVG, get TSX markup with React attribute names, style objects and the original SVG casing, ready to drop into a TypeScript component.
Loading SVG to TSX Converter...
SVG to TSX Converter - Convert SVG Icons to TypeScript React Components
Dropping an exported SVG straight into a .tsx file rarely compiles: stroke-width, class and style="…" are all wrong for React, and a lowercase viewbox quietly stops the icon from scaling. Paste the SVG here and you get markup that TypeScript accepts and React draws the same way the browser drew the file. Run it through the TSX formatter afterwards if you want your own code style, and use the TSX to SVG converter to go the other way.
How to Convert SVG to TSX - Step by Step Guide
Paste or Upload SVG Code
Copy the SVG from Figma (right-click, Copy as SVG), Illustrator, Inkscape or any text editor and paste it into the left editor, or click Upload and pick the .svg file. Icons, logos and full illustrations with gradients and filters all work. For other markup, try the HTML to TSX converter or the Markdown to TSX converter.
<!-- Example SVG code -->
<svg width="24" height="24" viewBox="0 0 24 24">
<path stroke-width="2" d="M12 2L2 7L12 12" />
</svg>Automatic Conversion to TypeScript TSX
The TSX appears on the right as soon as you stop typing. stroke-width becomes strokeWidth, fill-opacity becomes fillOpacity and class becomes className, while names that already have capitals (viewBox, gradientUnits, stdDeviation) are left exactly as they are. Attribute values, numbers included, are copied character for character. Working in plain JavaScript? The SVG to JSX converter gives you the same output as a .jsx file.
<svg width="24" height="24" viewBox="0 0 24 24">
<path strokeWidth="2" d="M12 2L2 7L12 12" />
</svg>SVG Attribute Conversions with TypeScript
Only the attributes React really spells in camelCase are renamed: stroke properties (stroke-width, stroke-linecap, stroke-linejoin), fill properties (fill-opacity, fill-rule), text properties (font-family, font-size, text-anchor), clipping (clip-path, clip-rule) and the xlink and xml namespaces (xlink:href, xml:space). data-* and aria-* attributes keep their dashes, because React expects them that way, and tabIndex becomes a number so TypeScript doesn't complain.
// Common attribute conversions:
stroke-width → strokeWidth
fill-opacity → fillOpacity
stroke-linecap → strokeLinecap
font-family → fontFamily
xlink:href → xlinkHrefCopy or Download TSX Component
Copy the TSX with one click or download it as icon.tsx. What you get is the <svg> element, not a whole component, so return it from a small function like the one below and spread the props onto the <svg> tag to make width, height and className configurable. The TSX validator can double-check the finished file, and the TSX minifier shrinks it if you need to.
const Icon = (props: React.SVGProps<SVGSVGElement>) => (
<svg width="24" height="24" viewBox="0 0 24 24" {...props}>
<path strokeWidth="2" d="M12 2L2 7L12 12" />
</svg>
);Frequently Asked Questions
How do I convert SVG to TypeScript React TSX?
Paste the SVG into the left editor or upload the .svg file. The TSX appears on the right a moment later: class becomes className, stroke-width becomes strokeWidth, style="…" becomes a style object, and SVG names such as viewBox, linearGradient and clipPath keep their capital letters, which React needs to draw them. The result is JSX markup that type-checks in a .tsx file. If you want it tidied up afterwards, run it through the TSX formatter.
Do I get a finished component with typed props?
No, you get the <svg> element itself. Put it inside a component and spread the props onto it, for example const Icon = (props: React.SVGProps<SVGSVGElement>) => (<svg {...props} …>…</svg>). That one type gives you width, height, className, onClick and every other SVG prop with autocomplete. If you already have plain JSX components to move over, the JSX to TSX converter adds the types for you.
Can I convert complex SVG graphics, not just icons?
Yes. Gradients, masks, clip paths, filters, <use> references, text with <tspan> runs, <style> blocks (including CDATA) and <foreignObject> all come through. Text inside <text> keeps its spaces, and braces or angle brackets in it are escaped so they show up as text instead of breaking the JSX. Numbers in attributes are copied exactly as written.
What happens to Inkscape, Illustrator and Figma extras?
Figma exports usually need nothing special. Illustrator files keep their xml:space and enable-background settings (the style gets a small cast so TypeScript accepts it). Inkscape and Sodipodi attributes such as inkscape:label are kept in a spread object, because JSX cannot write a name with a colon. Their editor-only elements, like <sodipodi:namedview>, are left out and the page tells you so; browsers never draw them anyway.
What if my SVG has a mistake in it?
SVG is XML, so it is parsed strictly. A missing closing tag, a bare & or an HTML entity like stops the conversion, and you get the line and column with a short explanation of what to change. Event attributes such as onclick are turned into arrow functions; the functions they call still have to exist in your own code.
Why use SVG as TSX instead of an <img> tag?
Inline SVG can be styled with currentColor and CSS, animated, and given props like any other component, and TypeScript checks every attribute you add later. The trade-off is a bigger JavaScript bundle for large illustrations, so keep detailed artwork as files and inline the icons. To turn TSX back into a standalone file, use the TSX to SVG converter.
Related Tools
TSX Formatter
Format and beautify TSX/TypeScript React code with proper indentation
TSX Fixer
Fix broken TSX automatically, repair TypeScript React component errors, type annotations, and JSX syntax
HTML to TSX Converter
Convert HTML to TSX/TypeScript React format instantly
Markdown to TSX Converter
Convert Markdown to TypeScript React TSX components for type-safe content
TSX Validator
Validate TSX syntax and TypeScript React component structure
TSX to JSX Converter
Convert TypeScript TSX to plain JSX
TSX Minifier
Minify TSX/TypeScript React code for production builds
TSX to HTML Converter
Convert React TypeScript TSX to standard HTML