Skip to content
FastTool

SVG Optimizer & Cleaner

Shrink SVG files, fix missing or clipped viewBox attributes, strip scripts and compare before and after side by side.

Runs in your browser. Nothing is uploaded.

SVG input & options

Edits update the preview and cleaned SVG right away.

2 suits web icons; 3 suits mm cut files.

Keep width and height for CAD, laser or vinyl cutters.

Cleaned SVG & preview

  • Original size 3,826 B
  • Cleaned size 655 B
  • Change −82.9%
  • CSS Data URI 853 B

Safety check

Looks good

No scripts, inline event handlers, unsafe links or outside fetches found.

Preview background

Original

3,826 B (3.7 KB)
Original SVG preview
no viewBox · 128px × 128px

Cleaned

655 B
Cleaned SVG preview
viewBox="0 0 128 128" · scales with CSS

Added viewBox="0 0 128 128" and rounded 45 numbers. Removed 22 editor/comment items, 1 hidden layer, 2 unused <defs>, 2 empty groups.

How to use

  1. The page opens with a bloated Inkscape icon loaded. Drop your own .svg file (up to 10 MB) or paste markup into the input box.
  2. Pick a decimal precision and sizing mode. Keep 2 decimals and responsive sizing for web icons, or keep width and height for laser and vinyl cutters.
  3. Check the side-by-side preview on checkerboard, light and dark backgrounds, with the dashed viewBox frame switched on.
  4. Read the safety check line to see if scripts, inline event handlers or outside image links were found and stripped.
  5. Select Download .svg, Copy SVG for inline HTML, or Copy CSS Data URI for stylesheets.

Worked example

Switch between the three presets at the top of the tool to compare each case right away.

Bloated icon export (default)

An Inkscape shield icon carries an XML header, DOCTYPE, RDF metadata, two unused gradients, a hidden guide layer and 6-decimal path numbers.

3,826 B drops to 655 B (−82.9%). It adds viewBox="0 0 128 128" and removes width="128px" height="128px" so CSS controls the size.

Clipped stroke without viewBox

A 24 × 24 badge draws a stroke-width="4" border right on 0 to 24, so 2 px of stroke clips off every outer edge.

651 B drops to 305 B (−53.1%). It sets viewBox="-2 -2 28 28", restoring the full 4 px border on all four sides.

Laser / plotter cut file

An 80mm × 50mm mounting plate holds hidden dimension lines, Inkscape tags and 6-decimal corner and slot arcs.

1,936 B drops to 542 B (−72.0%). At 3 decimals in Keep width, height and viewBox mode, every hole and arc stays true to 0.001 mm.

How it works

Your SVG is parsed into an XML tree in memory, cleaned pass by pass and drawn inside isolated <img> previews. Nothing leaves your browser.

Path rounding that protects elliptical arcs

Vector editors often write 6 decimal places on every point, such as M 12.000000,4.500000 L 28.333333,19.666667. We parse all ten W3C SVG 2 path commands from M through Z. Coordinates are rounded to your chosen decimals, and extra spaces and leading zeros are dropped.

Elliptical arcs (A and a) take seven values: rx ry angle large-arc-flag sweep-flag x y. Positions 4 and 5 are single-digit flags (0 or 1), so we keep them as exact integers and arcs never flip.

Fixing missing or clipped viewBox attributes

Without a viewBox, a fixed width and height locks an SVG to one pixel size. Because SVG strokes sit half inside and half outside a shape’s path, a border on the artboard edge also gets sliced in half:

painted min = path min − (stroke-width ÷ 2) painted max = path max + (stroke-width ÷ 2) 0..24 box with stroke-width 4 → −2 to 26 → viewBox="-2 -2 28 28"

We measure lines, cubic and quadratic curves, circles and rotated arcs, add half of any visible stroke width and write a viewBox that fits.

Unused <defs> and editor bloat

Design tools leave behind inkscape:, sodipodi:, Illustrator and RDF blocks, hidden construction layers and old gradients inside <defs>. We trace every url(#id) and href="#id" link—including gradients that point to other gradients—so used fills stay and orphaned ones go. Accessible <title> and <desc> tags stay untouched.

Safe previews and CSS Data URIs

An SVG file is XML and can carry <script> tags, onload attributes or javascript: links. Both previews load through Blob URLs inside <img> elements instead of inserting raw markup into the page. Script stripping also removes active tags and handlers by default. For CSS backgrounds, we build a UTF-8 percent-encoded url("data:image/svg+xml,...") string with single-quoted attributes, which is smaller than Base64.

Limits

This tool cleans structure and number precision; it does not merge overlapping shapes or simplify hand-drawn curves with thousands of anchor points. Embedded raster images (data:image/png;base64,...) stay unchanged; compress photos first in the Image Compressor. Text elements keep their font names, so convert display type to outlines in your editor if visitors lack that font.

Sources

FAQ

Why won’t my SVG scale when I change its width in CSS?

The root <svg> tag is missing a viewBox attribute and has fixed width and height values instead. Keep Sizing mode set to Responsive here: it adds the missing viewBox and removes width and height so the icon fills any CSS box.

Why are the outer edges of my SVG icon cut off?

SVG centers strokes on the path, so half of stroke-width reaches outside the shape. A 4 px stroke on a 0 0 24 24 box reaches from -2 to 26. Leave “Expand viewBox when outer strokes clip” ticked to widen the viewBox automatically.

Which sizing mode should I pick for Cricut, LightBurn or Inkscape?

Choose Keep width, height and viewBox and 3 decimal places. Cutting apps read width="80mm" height="50mm" alongside viewBox="0 0 80 50" to lock 1 user unit to 1 millimeter.

How many decimal places do web icons need?

Two decimals give a grid step of 0.01 user units—one hundredth of a pixel on a 24 × 24 or 128 × 128 icon. Use 1 decimal for large illustrations, 2 for UI icons and 3 for millimeter parts.

Can an SVG file contain JavaScript?

Yes. Unlike PNG or WebP, SVG is an XML document that can hold <script> elements, onload or onclick handlers and javascript: links. Keep script stripping turned on when cleaning icons from outside sources.

Why is the CSS Data URI UTF-8 text instead of Base64?

Base64 expands plain text by about 33%. Because SVG is already text, percent-encoding only unsafe characters such as #, < and > produces a shorter background-image rule that every modern browser reads.

Step by step: why an SVG gets cropped or refuses to scale, and how to fix viewBox.

Updated