Home › Developer Tools › SVG to JSX

SVG to JSX

Paste an SVG file or icon and get a ready-to-use React component. Attributes are converted to camelCase, inline styles become style objects, class becomes className and editor junk is stripped. Add props spreading, icon sizing, currentColor or TypeScript with one click.

Last updated:

Preview
Advertisement
Advertisement

How to use the SVG to JSX

  1. Paste your SVG code, drop an .svg file on the editor or press Upload.
  2. Name the component; it is filled in from the file name automatically.
  3. Pick the options: component style, TypeScript, props spread, size handling and currentColor.
  4. Check the output, which updates as you type, and the preview of your SVG.
  5. Copy or download the component as a .jsx or .tsx file and import it in your React app.

SVG attributes and their JSX names

React uses the JavaScript (DOM property) spelling of attributes. For SVG that mostly means removing hyphens and colons and capitalising the next letter. The most common conversions:

SVG attributeJSX propSVG attributeJSX prop
classclassNamestroke-widthstrokeWidth
fill-rulefillRuleclip-ruleclipRule
stroke-linecapstrokeLinecapstroke-linejoinstrokeLinejoin
stroke-dasharraystrokeDasharraystroke-opacitystrokeOpacity
fill-opacityfillOpacitystop-colorstopColor
clip-pathclipPathfont-familyfontFamily
text-anchortextAnchordominant-baselinedominantBaseline
xlink:hrefxlinkHref (or plain href)xml:spacexmlSpace
style="fill:red"style={{ fill: 'red' }}onclick="…"removed: use onClick with a function

Attributes that are already camelCase in SVG, such as viewBox, preserveAspectRatio and gradientUnits, stay the same. data-* and aria-* attributes also keep their hyphens.

Using the component

Save the output as CabinIcon.jsx (or .tsx) and import it like any other component. With the props spread enabled, everything you pass lands on the <svg> element:

import CabinIcon from './CabinIcon';

<CabinIcon className="nav-icon" aria-hidden="true" />
<CabinIcon width={32} height={32} onClick={openMenu} />

For icon sets, combine Icon: 1em × 1em with Use currentColor: the icon then follows the font size and text color of wherever it is placed, so one component works in buttons, menus and headings without extra props. Keep each icon's id values unique (for gradients and clip paths), because several copies of the same inline SVG on one page share the document's id namespace.

Frequently asked questions

Why can't I paste SVG directly into JSX?

JSX follows JavaScript DOM property names, not HTML attribute names. SVG attributes with hyphens or namespaces such as stroke-width, fill-rule and xlink:href must be written as strokeWidth, fillRule and xlinkHref, class must become className, and inline style must be an object. React warns about or ignores the original names.

How do I change the icon color from React?

Turn on Use currentColor. Every fill and stroke color is replaced by currentColor, so the icon takes the CSS color of its parent: <Icon style={{ color: 'tomato' }} /> or a className that sets color.

What does the props spread do?

It adds {...props} to the root <svg>, so anything you pass to the component, such as className, width, aria-label or onClick, is applied to the SVG and overrides the default attribute values.

What does icon size 1em do?

It sets width and height to 1em so the icon scales with the surrounding font size, like an icon font. The viewBox is kept (or created from the original width and height) so the drawing scales correctly.

Does it work with React Native?

The output is for React DOM. React Native needs the react-native-svg library, whose component names are capitalised (Svg, Path, Circle). The attribute conversion is the same, so you can rename the elements by hand.

Is my SVG uploaded?

No. The SVG is parsed and converted by your browser, and the preview is rendered locally as an image so scripts inside the file never run.

Are all the tools on FreeToolCabin tested for quality and accuracy?

Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.

Related tools

HTML to JSX ConverterConvert HTML to valid React JSX: className, htmlFor, style objects, self-closing tags and events.SVG OptimizerMinify SVG files: strip metadata, comments and editor junk, round numbers, compare sizes.SVG to PNGConvert SVG graphics to PNG or JPEG at any scale.JSON to TypeScriptGenerate TypeScript interfaces or types from JSON, with nested types and optional fields.Free Icon Search and DownloadSearch free open-source icons (Lucide, Tabler, Material), recolor, resize and get SVG or PNG.SVG EditorEdit SVG files visually: move shapes, change colors, text and strokes, add shapes, edit the code.Open Graph PreviewPaste OG tags and preview how links look on Facebook, X and LinkedIn.YouTube Embed Code GeneratorCreate responsive YouTube embed code with start time, autoplay, loop and privacy mode.CSS Box Shadow GeneratorDesign layered CSS box shadows with a live preview, presets and one-click Copy CSS.CSS Border Radius GeneratorRound each corner, draw elliptical 8-value radii or random blob shapes and copy the CSS.CSS Button GeneratorDesign CSS buttons with gradients, borders, shadows and hover and active states, then copy the code.CSS Flexbox GeneratorBuild flexbox layouts visually: set container and item properties, then copy the CSS and HTML.Twitter Card GeneratorCreate X / Twitter Card meta tags with Open Graph fallbacks, character counters and a live preview.CSS Grid GeneratorDraw CSS grid layouts: set tracks and gaps, drag to name areas, then copy the CSS and HTML.PX to REM ConverterConvert px to rem or em and back, with a 1-100px table and a whole-CSS converter.Glassmorphism CSS GeneratorDesign frosted-glass UI cards with blur, transparency and border sliders, then copy the CSS.CSS Text Shadow GeneratorLayer CSS text shadows with a live preview and neon, 3D, outline and retro presets.HTML Editor (Live Preview)Write HTML, CSS and JavaScript and see a live, sandboxed preview as you type.CSS Clip-Path GeneratorDraw CSS clip-path shapes by dragging points: polygons, circle, ellipse and inset. Copy the CSS.CSS Animation GeneratorCreate CSS keyframe animations from 23 presets with live preview, timing controls and Copy CSS.CSS Triangle GeneratorMake CSS triangles in 8 directions with the border trick or clip-path. Set size and color, copy CSS.CSS Loader GeneratorPick from 14 pure CSS spinners and loaders, set color, size and speed, then copy the HTML and CSS.Cubic Bezier GeneratorDrag the control points to design a CSS easing curve, compare it with linear and copy cubic-bezier().CSS Filter GeneratorAdjust blur, brightness, contrast, hue, sepia and drop-shadow on an image and copy the CSS filter.CSS Specificity CalculatorCalculate CSS selector specificity (a, b, c), including :is(), :not(), :has() and :where(), and compare.Google Maps Embed GeneratorTurn an address or coordinates into responsive Google Maps iframe embed code, no API key.Neumorphism CSS GeneratorDesign soft UI neumorphic shapes with live preview and copy the box-shadow CSS.SVG Wave GeneratorMake layered SVG waves for section dividers and export SVG, PNG or a CSS background.SVG Blob GeneratorGenerate random organic SVG blob shapes with gradients and export SVG, PNG or CSS clip-path.CSS Clamp GeneratorTurn min/max sizes and viewport widths into a fluid CSS clamp() value in rem and vw.CSS @font-face GeneratorTurn font files or URLs into ready-to-paste @font-face rules with weights, styles and a preview.CSS Media Query GeneratorBuild @media rules for widths, orientation, dark mode and hover, or get framework breakpoints.CSS Scrollbar GeneratorStyle scrollbars: width, colors, radius and hover, with ::-webkit-scrollbar and scrollbar-color CSS.CSS Sprite GeneratorPack many icons into one sprite sheet PNG and get CSS classes with background-position.CSS Text Gradient GeneratorMake gradient text with background-clip:text: color stops, angle, font preview and fallback CSS.CSS Toggle Switch GeneratorDesign pure-CSS toggle switches: size, colors, shape and animation. Copy accessible HTML + CSS.CSS Tooltip GeneratorBuild pure CSS tooltips: position, arrow, colors, padding and animation. Copy HTML and CSS.HTML Form BuilderDrag and drop form fields with labels and validation, then copy accessible HTML and CSS code.CSS Hover Effects GeneratorPick button, link and image hover effects, tweak colors and timing, and copy the HTML and CSS.CSS InlinerMove CSS from style blocks into inline style attributes so HTML emails render in every client.CSS Shape Divider GeneratorCreate wave, tilt, curve and triangle section dividers and copy the SVG, HTML and CSS.CSS Transform GeneratorRotate, scale, skew and translate an element with sliders and copy the CSS transform code.Font Pairing ToolPreview Google Font heading and body pairs on real layouts and copy the embed code and CSS.HTML Accessibility CheckerPaste HTML to find WCAG accessibility problems with impact level, the failing element and a fix.HTML Image Map GeneratorDraw clickable rectangle, circle and polygon hotspots on an image and get image map HTML.SVG ViewerOpen or paste SVG code to preview it live with zoom, backgrounds, size info and PNG export.Pathfinding VisualizerAnimate BFS, DFS, Dijkstra, A* and greedy search on a grid with walls, weights and mazes.Iframe GeneratorCreate iframe embed code: size or responsive ratio, border, allow, sandbox, lazy load, live preview.PX to VW ConverterConvert pixels to vw and vh for any viewport size, and vw/vh back to px, with breakpoint tables.SVG Path EditorEdit an SVG path d attribute visually: drag points, edit commands, convert, scale and minify.SVG to CSS Data URITurn SVG code into a small URL-encoded data URI for CSS backgrounds, with Base64 size comparison.Tailwind CSS Cheat SheetSearchable Tailwind class to CSS reference with live previews, class decoder and color palette.Web App Manifest GeneratorCreate a PWA manifest.json and every app icon size from one image, downloaded as a ZIP.CSS Background Pattern GeneratorMake pure-CSS stripes, dots, checkerboard, zigzag and grid backgrounds and copy the code.CSS Color Filter GeneratorTurn a HEX color into a CSS filter that recolors black icons and SVGs, with an accuracy score.CSS Gradient Animation GeneratorCreate animated gradient backgrounds: pick colors, angle and speed, preview live and copy the CSS.
See all 52 Web, HTML & CSS Tools →