SVG Code Formatter: Format SVG Code with Clean Indentation

Turn minified SVG into readable, indented markup. Only whitespace changes, never the image.

SVG Code Formatter tool

1Add your SVG

Drop your SVG here, or click to browse Or paste SVG code anywhere on the page. Nothing is uploaded.
No file?

2Adjust the options

3Preview and download

Live preview
sample.svg
Input and output codeView, edit and copy the code
Input SVG code
Output

Under the hood

How SVG Code Formatter works

An SVG code formatter turns minified or messy SVG into neatly indented, readable markup. Only whitespace changes, so the SVG renders exactly the same.

  1. <svg><g><path d="…"/></g></svg>

    Tokenize the markup

    The SVG text is split into tags, comments, text nodes and declarations without altering their content.

    Regex tokenizer
  2. <svg> <g> <path d="…"/> </g></svg>

    Indent by nesting depth

    Each opening tag increases the depth and each closing tag decreases it. You choose 2 spaces, 4 spaces or tabs.

    Depth counter
  3. Wrap attributes (optional)

    Elements with three or more attributes, or long lines, can have one attribute per line for easy diffing.

    Attribute splitter
  4. depth 1depth 2depth 3

    Show the structure

    A chart counts lines at each nesting depth, giving you a quick picture of how deep the SVG goes.

    Depth histogram
The four stages of the SVG Code Formatter, from your input to the finished file.

Why format SVG code

Easier reading and diffs
Indented code makes structure and changes obvious.
Rendering is unchanged
Whitespace between tags does not affect how SVG renders.
Your style
Pick 2 spaces, 4 spaces or tabs to match your project.

Step by step

SVG Code Formatter process

Four steps format an SVG. The preview confirms nothing changed visually.

  1. Paste your SVG code

    Drop a file or paste code. A one-line export is a great test.

    Tip: The input box shows your code.

    Drop SVG
  2. Choose indentation

    Pick 2 spaces, 4 spaces or tabs.

    Tip: The output reformats instantly.

    IndentWrapDepth
  3. Wrap attributes if needed

    Switch on One attribute per line for long tags.

    Tip: Helps code review.

  4. Copy or download

    Press Copy code or Download.

    Tip: Copying from the preview gives the full output.

    Download SVGsvg-code-formatter.svg

Use the SVG Code Formatter

Reference

SVG Code Formatter settings / conversion chart

The table lists formatting options. The chart explains the depth histogram.

Lines per nesting depth (example)

Lines per nesting depth (example)Depth 1: 2/5; Depth 2: 5/5; Depth 3: 4/5; Depth 4: 1/5.Depth 12/5Depth 25/5Depth 34/5Depth 41/5
Most SVG lines sit at depth 2–3, inside groups.

At a glance

  • Converts best: Depth 2.
  • Needs the most care: Depth 4.

Most SVG lines sit at depth 2–3, inside groups.

SVG Code Formatter options
OptionValuesEffect
Indentation2 spaces, 4 spaces, tabsWidth of each nesting level
One attribute per lineOff or onSplits long tags for readability
Text nodesKept inline when shortKeeps <text> readable
CommentsKeptFormatting never deletes them

Answers

SVG Code Formatter FAQ

Questions people ask about the SVG Code Formatter, answered for this specific use case.

Does formatting change how my SVG renders?

No. Only whitespace between tags changes.

Can I choose tabs instead of spaces?

Yes. Pick Tabs in the Indentation control.

Will it fix invalid SVG?

No. Use the SVG Validator to find problems.

Does it keep my comments?

Yes. Comments are left in place.

Is my code uploaded?

No. Formatting runs in your browser.

Ready to try it?

Your result is one drop away.

Open the SVG Code Formatter

All converters

Every free converter and SVG tool

43 free tools that run in your browser. Pick a converter below, or search by format or task.