Format SVG Online: Clean Up Logo and Favicon Code Without Changing the Artwork
How to format SVG code online for logos and favicons: pretty-print safely, keep path geometry intact, protect private artwork, and verify the result.
Contents
The short answer
To format SVG online, paste the file's source code into a browser-based SVG or XML formatter (also called a beautifier or pretty-printer), choose your indentation, turn off any optimization options, and copy the result back into a new .svg file. Formatting should only add line breaks and indentation so a person can read and edit the markup. It should not change how the logo or favicon looks. Before you trust the output, compare it with the original in a browser and confirm that only whitespace changed.
Some terms help define what formatting covers. An SVG (Scalable Vector Graphics) file is plain-text XML that describes shapes as instructions instead of pixels. The path element holds the geometry, and its d attribute is a string of drawing commands and coordinates. The viewBox attribute defines the internal coordinate system that the artwork scales from. Formatting rearranges the whitespace around these elements. It does not touch the instructions themselves.
Formatting, minifying and optimizing are different jobs
Many online SVG tools combine these three operations in one interface, often with optimization switched on by default. You need to know which one you are running, because only one of them leaves the artwork untouched.
| Operation | What it changes | Typical use |
| Formatting (pretty-printing) | Adds line breaks and indentation only | Reading, reviewing or hand-editing logo code |
| Minifying | Removes unneeded whitespace | Shrinking a finished file for delivery |
| Optimizing | Can remove metadata, merge shapes, round coordinates and rewrite path data | Reducing file size, accepting possible geometry changes |
If your goal is readable code, use formatting alone. Coordinate rounding and path rewriting belong to optimization. They can shift curve points slightly, which may be invisible at large sizes but noticeable in a precise logo mark or a tiny favicon. Treat optimization as a separate, deliberate step and review its output on its own.
What formatted SVG looks like
The two snippets below describe the same simple favicon: a rounded square with a letterform. The first is minified on a single line. The second is formatted. The attributes and path data are identical in both.
<svg viewBox="0 0 32 32"><rect width="32" height="32" rx="6" fill="#1a1a1a"/><path d="M9 23V9h8a5 5 0 0 1 0 10h-4v4z" fill="#fff"/></svg>
<svg viewBox="0 0 32 32">
<rect width="32" height="32" rx="6" fill="#1a1a1a"/>
<path d="M9 23V9h8a5 5 0 0 1 0 10h-4v4z" fill="#fff"/>
</svg>
For brevity, both snippets omit the SVG namespace declaration, which is the xmlns attribute on the root svg element. A standalone .svg file, including one referenced as a favicon, needs that declaration so browsers parse it as SVG. SVG written inline inside an HTML page does not need it.
Step by step: formatting an SVG logo or favicon online
- 1. Keep the original. Duplicate the file and work on the copy so you can compare the two later.
- 2. Open the copy in a plain-text editor and look at the contents. A .svg extension does not prove the file is pure vector. If you find an image element or a long base64 data string, a raster picture is embedded inside, and formatting will not make that part scalable or editable.
- 3. Decide whether the artwork can go to a third party. Pasting code into a web tool may send it to that tool's server. For unreleased or client-owned logos, use a formatter that states it processes code locally in the browser, or use the built-in format command of an offline code editor.
- 4. Paste the code and set the indentation, for example two spaces, four spaces or tabs. Match whatever convention your project already uses.
- 5. Turn off every optimization option, such as removing metadata, rounding numbers, collapsing groups or converting shapes to paths, unless you deliberately want those changes.
- 6. Run the formatter, copy the output and save it as a new .svg file with UTF-8 text encoding.
- 7. Verify the result using the checks below before you replace any delivered file.
How to verify the formatted file
- Open the original and the formatted file side by side in a browser. They should look the same at large size and at the small sizes where a favicon actually appears.
- Run a text comparison (diff) tool set to ignore whitespace. With that setting, it should report no differences. Any reported change means something beyond formatting happened.
- Check that the file is still well-formed XML. Every element must be closed, and the browser should not show a parsing error.
- Confirm that the root element still carries the namespace declaration and the same viewBox values as the original.
- If the file contains text elements, check that letter spacing and line content are unchanged. Some formatters add or remove whitespace inside text nodes, and that whitespace can affect rendered text.
Favicon-specific points to keep intact
SVG favicons often include an embedded style element, for example a prefers-color-scheme media query that swaps colors in dark mode. A formatter should indent the style block without rewriting the CSS inside it. Check that the selectors and colors survived. A square viewBox is a common design recommendation for favicon artwork, because browsers display the icon in a square space. Formatting does not change the viewBox. Fix proportions in the artwork itself, not in the code layout.
Formatting is also a good moment to review the code before delivery. Readable markup makes it easier to spot leftover editor metadata, hidden layers, unused definitions or stray embedded images. Whether to remove them is a separate decision, and it belongs to the optimization stage.
Limits of this guide
No verified evidence was available on specific online SVG formatters, their privacy practices or their default settings, so this guide does not recommend any particular tool. Check a tool's own documentation for how it handles your data and which options are enabled by default. Formatting a logo file does not grant permission to reuse or modify that logo. Usage rights depend on the owner's license or agreement, not on the file format.