1. Home
  2. Design tools
  3. SVG to React, Vue & Astro Component

SVG to React, Vue & Astro Component

Paste an exported icon and get a component you can import, with props for size, class and color.

Free, no sign-up. Runs in your browser: nothing is uploaded.

How to use SVG to React, Vue & Astro Component

  1. Paste or open the SVG.
  2. Choose React, Vue 3 or Astro and the options.
  3. Copy or download the component.

Features

  • React JSX and TypeScript
  • Vue 3 single-file component and Astro
  • Attribute names converted (strokeWidth, className)
  • Inline style to object
  • currentColor option and size removal
  • Editor metadata and comments dropped

Supported formats

Input

  • SVG code
  • SVG files

You get

  • React JSX or TSX
  • Vue 3 component
  • Astro component

Private by design

Everything you enter is processed by your browser on this device. Nothing is sent to openWorkstand or anyone else, so the SVG to React, Vue & Astro Component is safe for private and work data. After you have used it once while online, it also works without an internet connection. How local processing works

Good to know

  • Script elements and event attributes are kept; convert trusted SVG only.
  • Style blocks are not scoped to the component.

Guide

Turning raw SVG into React, Vue and Astro components

Designers export icons as SVG files, and developers want them as components that accept a size, a colour and a class name. Pasting an SVG straight into JSX does not work, because React uses a different attribute vocabulary from HTML and SVG, and a style string is not allowed at all. Doing the conversion by hand for each icon is dull and error-prone. This page converts one SVG at a time to a component for React, Vue 3 or Astro and shows exactly what changed.

What React needs

In JSX, attributes are JavaScript property names. stroke-width becomes strokeWidth, stop-color becomes stopColor, class becomes className and xlink:href becomes xlinkHref. A style attribute written as style="color: #111827; stroke-linejoin: round" must be an object, style={{ color: '#111827', strokeLinejoin: 'round' }}. Self-closing tags need the closing slash. The converter handles all of these, and tells you in a note which attribute names it renamed.

A worked example

Press Sample to load a 24 by 24 bell icon with an XML declaration, a comment, a title, a gradient and a circle filled with it, named BellIcon. The React TypeScript output starts import type { SVGProps } from 'react'; and then export function BellIcon(props: SVGProps<SVGSVGElement>) {. The root is <svg width="24" height="24" viewBox="0 0 24 24" fill="none" className="icon icon-bell" style={{ color: '#111827', strokeLinejoin: 'round' }} {...props}>. The path now has strokeWidth="2" and strokeLinecap="round", the gradient stops have stopColor, and the circle keeps fill="url(#dot)". The note reads that the class attribute was renamed to className.

Props, size and colour

The {...props} at the end of the root element passes whatever you give the component onto the SVG, so <BellIcon width={32} className="text-red-500" /> works. Because props come last, they override the sizes in the file. Tick Remove width and height to drop the fixed 24 by 24 entirely; the icon then scales with its container through the viewBox, and you set the size in CSS. Tick “Use currentColor” and every hard-coded fill and stroke colour becomes currentColor, so in the sample the two stroke="#111827" lines turn into stroke="currentColor" and the icon follows the CSS text colour. Gradient fills such as url(#dot) are not changed, and neither is the color in the style attribute.

Vue and Astro

Vue 3 output is a single-file component: a script setup block with defineOptions({ name: 'BellIcon', inheritAttrs: false }) and a template whose svg uses v-bind="$attrs". Attribute names stay as in the original, since Vue accepts SVG names, and class and style remain strings. Astro output has a frontmatter block typing Astro.props and spreads them onto the svg, so you pass attributes the same way. Neither of the two needs a conversion of attribute names.

Edge cases

Ids inside the SVG, such as the gradient dot, are global in the page. If you render two copies of an icon on one page the ids repeat; this is harmless when both gradients are identical but a hazard if they differ. The title element supplies an accessible name; keep it for meaningful icons, and remove it, together with aria-hidden, for decorative ones.

Limits

The converter works on one SVG. It does not optimise paths, so run the SVG Optimizer first for the smallest components. It does not remove script elements or inline event handlers, so only convert SVG you trust. Text elements keep their fonts. Everything is processed in your browser.

Checked against the current version of the SVG to React, Vue & Astro Component on .

Frequently asked questions

Why does React warn about invalid DOM properties when I paste an SVG?

React expects camelCase property names, so stroke-width, fill-rule, clip-path and class are reported as unknown attributes. Converting them to strokeWidth, fillRule, clipPath and className removes the warnings and makes the markup work.

Should I convert every icon into its own component?

For a handful of icons that is fine. For hundreds, a sprite sheet or an icon library with tree shaking keeps the bundle smaller and the build faster than hundreds of separate component files.

Why does a raw SVG fail in JSX?

JSX needs camelCase names for many attributes (stroke-width becomes strokeWidth, class becomes className) and an object for style. This page makes those changes.

Is the output safe for untrusted SVG?

Not by itself. Script elements and event attributes are kept, so convert only SVG you trust or clean it first.

Keep working with the result

openWorkstand also includes a free workspace with documents, spreadsheets, tasks, projects and a calendar that save to a folder on your computer.