Skip to main content
CalcChef

SVG Code Viewer

Paste SVG code to preview it as an image with scripts, event handlers and outside links removed, list its colors and elements, minify it or export React TSX. How it works

Use the SVG Code Viewer

Preview
Preview will appear here
Try an example:

About the SVG Code Viewer

Paste SVG markup and the viewer draws it as an image after removing scripts, event handlers such as onload, links, animation, foreignObject and references to other files, while plain <style> rules and filter primitives stay. It lists everything it removed, the viewBox, size, element counts and colors, and can minify the markup, export it as a React TSX component or save it as a PNG at 1x to 4x. The preview zooms to Fit, 100%, 200% or 400% on a theme, white, dark or checkerboard background.

What the sanitizer removes from a test file

RemovedKind
onloadattribute
<script>element
<a>element
fillattribute
<animate>element
<foreignobject>element
hrefattribute
<style>element

Test file: an <svg onload>, a <script>, an <a> link around a rect whose fill is url(https://...), an <animate>, a <foreignObject>, an <image href="https://..."> and a <style> with @import. Kept from the same file: a circle with style="fill:#0f0", a <style> with .a{fill:#00f} and a filter with feDropShadow.

SVG attributes in the React (TSX) export

SVGReact export
stroke-widthstrokeWidth
classclassName
xlink:hrefxlinkHref
xml:spacexmlSpace
text-anchortextAnchor
font-familyfontFamily
clip-pathclipPath
aria-labelaria-label
fill-rulefillRule
style="fill:#fff;stroke-width:2"style={{ fill: "#fff", strokeWidth: "2" }}

data-* attributes never reach the export: the sanitizer removes them first and lists them in the Sanitization panel.

The three examples on the page

ExampleColors listedResponsiveItems removed
Basic Circle#6366f1, white, #4338caNo0
Gradient Star#7c2d12, #f59e0b, #ef4444No0
Responsive Icon#22c55e, whiteYes0

Responsive means the SVG has a viewBox and no fixed width and height, so it scales to its container.

Frequently asked questions

How do I preview SVG code?
Paste the markup into SVG Input, or press one of the examples. The preview updates a moment after you stop typing and is drawn as an <img> from a data URL of the sanitized markup. Copy, Download (image.svg) and the React export use the same sanitized markup.
What does the sanitizer remove from an SVG?
<script>, event handlers such as onload, <a> links (the shapes inside stay), <foreignObject>, animation elements, feImage, href values other than #id (PNG, JPEG, GIF or WebP data URLs on <image> are kept), data-* attributes, and any attribute that points to another file. The Sanitization panel lists each removed item with a count and the reason.
How do I convert SVG to a React component?
Press Export React. The tool writes TSX: export function SvgIcon(props: React.SVGAttributes<SVGSVGElement>) returning the <svg> with its own attributes first and {...props} after them, so props you pass override them. Hyphenated names become camelCase (stroke-width is strokeWidth), class becomes className, and aria-* attributes stay as written. data-* attributes are not in the export, because the sanitizer has already removed them.
Are <style> blocks and style attributes kept?
Yes, when every declaration passes a filter: no @import, no url() other than url(#id), no backslash, no expression(), behavior, javascript: or -moz-binding. So .a{fill:#00f} from Illustrator keeps its colors, while a <style> with @import url(x.css) is removed as a whole and listed.
How do I convert SVG to PNG?
Paste the SVG, pick PNG at 1x, 2x, 3x or 4x and press Download PNG. The size is the SVG’s own width and height times the scale, so a 24 by 24 icon at 4x saves as 96 by 96 px. The longest side is capped at 8,192 px: 5,000 by 2,000 at 2x becomes 8,192 by 3,277. The PNG is drawn from the sanitized markup, and areas the SVG leaves empty stay transparent whatever preview background you chose.
Why did my filter="blur(5px)" disappear?
The paint and reference attributes (fill, stroke, filter, mask, clip-path, marker-*) keep only none, currentColor, a plain color, an rgb() or hsl() color or url(#id). A CSS function such as blur(5px) or circle() in those attributes is removed and listed; define the filter as a <filter> element and refer to it with url(#id).

Related Tools

View all tools