SVG to Code: Base64, Data URI, HTML, React and Vue

Paste an SVG once and copy it out in five shapes. The markup is re-serialised and the attribute names are rewritten for each target — stroke-width becomes strokeWidth, class becomes className — so the React and Vue tabs paste straight into a component.

No upload5 outputsByte sizesCopy & download

1. Source SVG

empty
Drop an .svg file here, or

2. Output

Paste an SVG to see the output.
chars — bytes — source —

Attribute names are rewritten per target — the drawing itself is never touched.

The same SVG needs different markup in each place you paste it: a data URI for CSS, inline elements for HTML, and camelCase attribute names plus className for React — pasting raw SVG into JSX is the single most common reason an icon renders blank.

What each of the five outputs is for

Why attribute conversion matters

JSX is not HTML. Two things break when you paste raw SVG into a component: hyphenated attribute names are read as invalid identifiers, and class collides with the JavaScript reserved word. React therefore expects strokeWidth, strokeLinecap, strokeLinejoin, fillRule, clipRule, stopColor, textAnchor and className. Namespaced attributes follow the same rule: xlink:href becomes xlinkHref, and xml:space becomes xmlSpace.

A second trap is the style attribute. React wants an object, not a CSS string, so style="fill:#5850EC;stroke-width:2" has to become style={{fill:'#5850EC', strokeWidth:2}}. The React tab rewrites inline styles that way and leaves everything else as a string.

Data URI or inline SVG?

Inline SVG saves a request and can inherit currentColor, which is why icon systems inline their icons. The price is bytes in the HTML: each inlined icon is downloaded with the document, uncached separately, and repeated on every page that uses the same markup. A data URI in CSS is cached with the stylesheet, which is a better deal for decorative background patterns that repeat across pages.

Base64 inflates the payload by roughly 33% because three bytes become four characters. Percent-encoding is usually smaller for SVG, since most of the markup is ASCII that survives untouched — only #, <, > and quotes need escaping. The byte counter under each output shows both numbers for your own file, which settles the argument faster than any rule of thumb.

Cleaning before you embed

Every output here strips the XML declaration and comments, because they are wasted bytes in an inline context. For the rest, run the file through the SVG compressor first: it removes editor metadata, collapses groups and rounds path precision, and the result is smaller in all five formats. If the icon should follow the text colour, replace hard-coded fills with currentColor in the colour changer, then re-generate the code here.

Privacy

Parsing uses DOMParser, encoding uses TextEncoder and btoa, and all of it runs in the tab. There is no upload endpoint and no request per keystroke, so an unreleased logo never leaves the device.

The same SVG shown as a React JSX component with stroke-width converted to strokeWidth and class converted to className
Five tabs, one source: the React output rewrites attribute names and keeps the geometry · swipe to see it all

Frequently asked questions

What is the difference between Base64 and a Data URI for SVG?

Base64 is the raw encoded payload. A data URI is the full string a browser can load, either data:image/svg+xml;base64,... or the percent-encoded data:image/svg+xml,... form. The data URI is what goes into an img src or a CSS url().

Why do I need React or Vue output instead of plain SVG?

Because JSX and Vue templates reject some SVG attribute names. JSX wants className instead of class and camelCase names such as strokeWidth and fillRule. This tool rewrites those names, which is the part that usually breaks a hand-pasted icon.

Is my SVG uploaded?

No. The markup is parsed and re-serialised in the tab with DOMParser, TextEncoder and btoa. Nothing is posted to a server, so confidential artwork stays on the device.

Does inline SVG perform better than an image tag?

Inline SVG saves a request and can be styled or animated with CSS, at the cost of bytes in the HTML document. Inline small icons you recolor with currentColor; keep large illustrations in an img tag or a data URI so the document stays small.

Why is the Base64 version larger than the file?

Base64 encodes three bytes as four characters, so the payload grows by about 33%. Compression on the wire usually brings it back down, but for icons a percent-encoded data URI is smaller than Base64.

Related SVG workflows

More free SVG tools