How to use
- Paste or type SVG code in the left box. You can also drop an
.svgfile on the area above and its code fills the box. - The preview on the right changes as you edit. To see transparent areas, switch the background between checker, white and dark.
- If the code has a syntax error, you get the line and column. While an error exists, the last working preview stays on screen, dimmed.
- Use the buttons below to clean up the code or add shapes, then download with Save SVG or Save PNG.
What this tool does, and what it does not
SVG Optimizer on this site shrinks files, while this tool tidies code so people can read and edit it. They pull in opposite directions, so use them together: edit here first, and compress last.
| What you want | Where |
|---|---|
| Edit code and see the result, find where an error is | This tool |
| Tidy indentation, add viewBox and xmlns, trim extra margin | This tool |
| Shrink the file by dropping comments and metadata, make a Data URI | SVG Optimizer |
| Choose resolution and background carefully and save as PNG or JPG | SVG to PNG |
It is not a drag-and-draw graphics editor. The shape buttons only insert one line of code, and you change the geometry and colors in the code.
Cleanup buttons
| Button | What it does |
|---|---|
| Tidy indentation | One tag per line, two spaces per level. Content inside <text>, <style>, <script>, <title> and <desc> is left untouched. |
| Add xmlns | Adds xmlns="http://www.w3.org/2000/svg" if missing. Without it, a .svg file or an <img> will not render. |
| Create viewBox | Builds a viewBox from width and height when none exists, so later resizing scales instead of cropping. |
| Remove width/height | Deletes both and keeps the viewBox, so the image stretches to its container. |
| Apply size | Enter only width or only height and the other is computed from the viewBox ratio. With viewBox 0 0 40 20 and width 100, the height is 50. |
| Crop viewBox to content | Measures what is actually painted and sets the viewBox to that area. A padding value adds that much on every side. |
How cropping the viewBox works
The SVG is drawn as an image and the bounds of the non-transparent pixels are located. The first pass draws an area five times the current one to find the rough position, and the second pass magnifies just that region and measures again. The result is the visible extent, including stroke width and glyph shapes, with an error around 0.1% of the content size. For example, on an SVG with viewBox 0 0 100 100 whose content actually spans 30 by 40 starting at (10, 20), a padding of 5 gives the viewBox 5 15 40 50. If width and height are both given in px, the width is kept and the height is adjusted to the new ratio.
If there is a background rectangle with width="100%", or the content is far too large, the tool reports that it cannot measure the bounds. Remove that element and try again.
A safe preview
The preview draws the SVG as an <img>, so scripts inside it do not run and external addresses are not loaded. If the code contains scripts or attributes such as onclick, you still get a warning, because the saved file can run them when opened directly in a browser. Read the code of an SVG you do not trust before using it.
Frequently asked questions
I pasted code but there is no preview.
Look for an error message first. Mismatched tags and unquoted attribute values are the usual causes. Write & as & and < as < inside text.
The saved SVG file shows nothing when I open it.
The xmlns attribute is probably missing. This happens often when code written for inline use in HTML is saved as a file. Press Add xmlns to fix it.
My icon has too much empty space around it.
Use Crop viewBox to content. A padding of 0 hugs the artwork, and 1 or 2 keeps strokes from being clipped.
Can I draw shapes by dragging?
No. This is a code editor. Insert a basic shape with the buttons, then change its numbers and colors in the code. For drawing artwork itself, a dedicated vector graphics program is a better fit.
How do I make the file smaller?
Use SVG Optimizer to remove comments and unneeded code. To embed an image straight into CSS or HTML, try Image to Base64.
Related tools
SVG Optimizer | SVG to PNG | SVG to PDF | HTML CSS JS Playground | Color Picker
The SVG you enter is processed only in your browser and never sent to a server.