Skip to content
Esc
  • MQTT Topic MatcherTest MQTT topic filters with + and # wildcards against topics, and check ACL patterns.
  • JSON FormatterBeautify, minify and validate JSON instantly as you type.
  • JSON DiffCompare two JSON documents and see every added, removed and changed value by path.
  • JSON to TypeScriptGenerate TypeScript interfaces or Zod schemas from a sample JSON response.
  • Base64 Encoder/DecoderConvert text to Base64 and back, with full Unicode support.
  • UUID GeneratorGenerate random v4 UUIDs — one or many — in the format you need.
  • JWT DecoderDecode JSON Web Tokens to inspect the header, payload and expiry.
  • Timestamp ConverterConvert Unix timestamps to dates and dates to timestamps.
  • URL Encoder/DecoderPercent-encode and decode URLs, and break down query strings.
  • Hash GeneratorGenerate MD5, SHA-1, SHA-256 and SHA-512 hashes of text or files.
  • Regex TesterTest regular expressions with live match highlighting and groups.
  • YAML to JSON ConverterConvert YAML to JSON and JSON to YAML, with clear error locations.
  • SQL FormatterBeautify or minify SQL for PostgreSQL, MySQL, SQL Server and 9 more dialects.
  • Mock Data GeneratorGenerate realistic fake data for API mocks as JSON, CSV or SQL inserts.
  • HTTP Header AnalyzerGrade response headers: CSP, HSTS, cookies, CORS and caching, explained.
  • Webhook Signature VerifierVerify and generate webhook signatures for GitHub, Stripe, Slack, Shopify and more.
  • Cron Expression GeneratorBuild and explain cron schedules, with the next run times in any time zone.
  • .env File ValidatorFind syntax errors, duplicates and missing keys in .env files.
  • HTML to JSX ConverterConvert HTML to valid React JSX: className, style objects, self-closing tags.
  • SVG to React ComponentTurn SVG files into React icon components with props and currentColor.
  • Markdown EditorWrite Markdown with a live preview, GitHub tables and task lists, and HTML export.

↑ ↓ to moveEnter to openPaste data to open it in the right tool. Nothing leaves your browser.

SVG to React Component

Paste an SVG to get a ready-to-use React component. Attributes are converted, editor clutter is removed, and props pass through to the <svg>.

Last updated

SVG

WifiIcon.tsx

Converted
import type { SVGProps } from "react";

export default function WifiIcon(props: SVGProps<SVGSVGElement>) {
  return (
    <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...props}>
      <path d="M5 12.55a11 11 0 0 1 14.08 0" />
      <path d="M1.42 9a16 16 0 0 1 21.16 0" />
      <path d="M8.53 16.11a6 6 0 0 1 6.95 0" />
      <circle cx="12" cy="20" r="1" fill="currentColor" />
    </svg>
  );
}

Hard-coded fill and stroke colours were replaced with currentColor, so the icon inherits the text colour.

How to use the SVG to React Component

  1. Paste the SVG

    Open the .svg file in a text editor or export it from your design tool, and paste the code.

  2. Name the component

    Give it a PascalCase name such as WifiIcon.

  3. Pick options

    TypeScript or JavaScript, currentColor for theming, and whether to drop width and height.

  4. Save the file

    Download WifiIcon.tsx (or .jsx) and import it like any component.

Features

  • Generates a complete component that spreads props onto the <svg>
  • TypeScript output typed with SVGProps<SVGSVGElement>, or plain JavaScript
  • Converts attributes to JSX: stroke-width → strokeWidth, class → className, xlink:href → xlinkHref
  • currentColor option replaces hard-coded fill and stroke colours so icons follow the text colour
  • Optionally removes width and height so the icon can be sized with CSS
  • Removes XML declarations, comments, <metadata> and Inkscape / Sketch attributes
  • Pretty-prints the markup, even from minified SVGs

Privacy

Your SVG is processed by JavaScript in your browser tab. Nothing is uploaded or stored, and the page's security policy blocks it from sending data to any other site.

Read the DevNest privacy policy

Examples

  • An icon with currentColor

    The stroke colour becomes currentColor, so the icon follows the text colour.

    SVG

    <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="#0f172a" stroke-width="2" stroke-linecap="round"><path d="M5 12.55a11 11 0 0 1 14.08 0"/><path d="M8.53 16.11a6 6 0 0 1 6.95 0"/><circle cx="12" cy="20" r="1"/></svg>

    WifiIcon.tsx

    import type { SVGProps } from "react";
    
    export default function WifiIcon(props: SVGProps<SVGSVGElement>) {
      return (
        <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" {...props}>
          <path d="M5 12.55a11 11 0 0 1 14.08 0" />
          <path d="M8.53 16.11a6 6 0 0 1 6.95 0" />
          <circle cx="12" cy="20" r="1" />
        </svg>
      );
    }
    
  • Clean up an Inkscape export

    Editor metadata is removed and the style string becomes an object. JavaScript output.

    SVG

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <svg xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" sodipodi:docname="bolt.svg" inkscape:version="1.3">
      <sodipodi:namedview id="base" />
      <path style="fill:#f59e0b;stroke:none" d="M13 2 3 14h9l-1 8 10-12h-9z" />
    </svg>

    BoltIcon.jsx

    export default function BoltIcon(props) {
      return (
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" {...props}>
          <path style={{ fill: "#f59e0b", stroke: "none" }} d="M13 2 3 14h9l-1 8 10-12h-9z" />
        </svg>
      );
    }
    
  • A multi-colour logo

    currentColor is off, so the brand colours stay. Width and height are left to CSS.

    SVG

    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><rect width="32" height="32" rx="7" fill="#6366f1"/><circle cx="16" cy="16" r="6" fill="#ffffff"/></svg>

    Logo.tsx

    import type { SVGProps } from "react";
    
    export default function Logo(props: SVGProps<SVGSVGElement>) {
      return (
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" {...props}>
          <rect width="32" height="32" rx="7" fill="#6366f1" />
          <circle cx="16" cy="16" r="6" fill="#ffffff" />
        </svg>
      );
    }
    

Understanding SVG icons in React

Why turn SVGs into components?

An inline SVG component can be styled with CSS (colour, size, hover effects), needs no extra network request, and accepts props like className, aria-label and onClick. Using <img src="icon.svg"> is simpler, but you can't change the icon's colour from your CSS.

import WifiIcon from "./WifiIcon";

<WifiIcon className="size-5 text-sky-500" aria-hidden="true" />

Theming with currentColor

currentColor makes a fill or stroke use the element's CSS color. With the currentColor option on, the icon inherits the colour of the text around it, so one component works on light and dark backgrounds and in hover states. Leave it off for multi-colour illustrations and logos.

Accessibility

  • Decorative icons next to text: pass aria-hidden="true".
  • Icons that carry meaning on their own: pass role="img" and an aria-label.
  • Icon-only buttons: put the label on the <button>, not the SVG.

Frequently asked questions

How do I change the icon's colour?

Turn on currentColor, then set the CSS color of the icon or its parent, for example className="text-red-500". Without currentColor, the colours written in the SVG are used.

How do I resize the component?

Pass width and height props, or turn on Remove width / height and size it with CSS. The viewBox keeps the proportions either way.

Is this the same as SVGR?

It does the same core job as SVGR's default template — a component that spreads props onto the svg — in your browser, without installing anything. SVGR adds build-time integration and SVGO optimisation.

Why were some attributes removed?

Design tools add metadata such as inkscape: and sodipodi: attributes and <metadata> elements. They don't affect rendering and aren't valid in JSX, so they're removed. The notes list everything that changed.

Does it optimise the SVG paths?

No. Paths are kept exactly as they are. Run the file through an optimiser such as SVGO first if you want smaller paths.