Start a project

Tool 26 of 57 · Images

SVG to JSX & Data URI

Paste an icon's SVG and get a clean React component with camelCase attributes, plus a small data URI and the CSS to use it as a background.

SVG to JSX & Data URI at a glanceIllustration: 1, An SVG; 2, processed in your browser; 3, JSX + data URI.SVG to JSX & Data URI1An SVG</>3JSX + data URI2In yourbrowser
1 An SVG 2 processed on your device 3 JSX + data URI

SVG to JSX & Data URI

Your SVG

Preview of your SVG
Preview

Results

React component
Data URI
CSS background

01

What it does

Turns SVG code into a React component, a compact data URI and a CSS background in one go.

  • Attributes renamed for JSX (stroke-width to strokeWidth, class to className)
  • Inline styles turned into style objects
  • TypeScript component option
  • currentColor swap so icons follow the text colour

02

Private by design

Everything happens in your browser. Nothing you type, paste or upload is sent anywhere, and it keeps working offline once the page has loaded.

03

What you get

JSX or TSX, a data URI and CSS, with a Copy and a Download button on every result.

  • React
  • JSX
  • SVG

Why it matters

Icons in React apps are usually SVG components, but pasting raw SVG into JSX breaks: class must become className, stroke-width becomes strokeWidth, and style strings must become objects. Fixing that by hand for every icon is tedious.

For plain HTML and CSS, an SVG data URI avoids an extra request for small icons. URL-encoding it, rather than Base64, keeps it about a third smaller and still readable.

How it works

  1. InputSVG code
  2. In your browserParsed, cleaned and rewritten for React
  3. OutputA JSX or TSX component, a data URI and CSS

Where it fits in a designer's workflow

  1. Plan
  2. Design
  3. Build
  4. Test
  5. Launch
Turning icons into components while building.

By the numbers

The sample icon as text and as data URIsSVG text: 300 bytes; Data URI, URL-encoded: 335 bytes; Data URI, Base64: 426 bytesSVG text300 bytesData URI, URL-encoded335 bytesData URI, Base64426 bytes
Measured with this tool's own encoder. URL-encoding an SVG adds only a little, while Base64 adds about a third, so for SVG the URL-encoded data URI is usually the smaller choice. Source: RFC 2397: data URLs.
Show the numbers as a table
FormBytes
SVG text300
Data URI, URL-encoded335
Data URI, Base64426

How to use it

  1. Paste your SVG, or keep the example.
  2. Name the component and choose JSX or TSX.
  3. Tick the options you want, such as currentColor.
  4. Copy or download the component, the data URI or the CSS.

FAQ

Should I optimise the SVG first?

Yes, for exported icons. Run it through the SVG Optimiser to remove editor data, then convert it here.

Why URL-encode instead of Base64?

SVG is text, so URL-encoding only escapes a few characters and the result stays about 30% smaller than Base64. Base64 is there for tools that need it.

Are scripts kept?

No. Script tags and on… event attributes are removed from all the outputs.

Does it work with React Native?

The JSX uses web SVG elements. For React Native you'd use react-native-svg, which needs capitalised element names.

Work with me

Want a site that gets these right?

I build fast, accessible websites and web apps that pass these checks from day one. Tell me about your project and I'll reply personally with honest next steps.

All developer tools · Back to leej.uk