How to Format or Minify XML
Paste XML into the input area
Drop your XML into the left input box. The tool reads it with the browser's built-in DOMParser, so everything stays on your device and nothing is uploaded. A single unformatted line works fine - the parser handles the structure for you.
Pick an indent and a mode
Set Indent to 2 spaces, 4 spaces, or Tab, then choose Mode. Format expands the XML with line breaks and nesting; Minify collapses it to one compact string. The indent setting only applies in Format mode.
Click Format XML, then Copy
Press Format XML to render the result on the right. If the input parses cleanly you get a success message; use Copy to send the output to your clipboard, or Clear to reset both panels and start over.
Format Mode vs Minify Mode
Both modes first parse your XML with DOMParser and re-serialize it, so the data stays identical. The difference is only in the whitespace they produce and where each output is best used.
| Aspect | Format (pretty-print) | Minify |
|---|---|---|
| Line breaks | One element per line | Removed |
| Indentation | 2 spaces, 4 spaces, or Tab | None |
| Output size | Larger, more readable | Smallest possible |
| Best for | Debugging, code review, editing by hand | API payloads, storage, data transfer |
| Whitespace between tags | Added to show hierarchy | Stripped between tags |
| Data and structure | Unchanged | Unchanged |
Which Setting Should You Use?
Reading and debugging
Use Format mode with 4 spaces. The wide indentation makes deep nesting easy to scan and is the most common convention for XML config and data files.
Matching a code base
Choose Tab if your project indents with tabs, so the formatted output drops straight into source control without reformatting diffs. Pick 2 spaces for more compact, screen-friendly nesting.
Shipping to an API
Switch to Minify mode. It removes line breaks and collapses runs of whitespace into single spaces, producing a compact string that is lighter to send and store.
Checking validity quickly
Paste and click Format. Because the tool parses with DOMParser before output, an invalid document is reported with the first parse error instead of being formatted, giving you a fast sanity check.
Common Problems and Fixes
It says "Invalid XML" and shows no output
The DOMParser found a syntax problem - usually an unclosed or mismatched tag, an unquoted attribute, a stray ampersand, or more than one root element. Fix the spot named in the error message and click Format XML again.
Indentation looks slightly off on mixed content
The formatter indents based on opening and closing tags. Elements that mix text and child tags on the same line can produce uneven spacing. Splitting that content into separate child elements gives cleaner nesting.
My indent choice did nothing
The indent size only affects Format mode. In Minify mode all whitespace is stripped, so 2 spaces, 4 spaces, and Tab all produce the same compact line. Switch back to Format to see indentation.
A very large file feels slow or stalls
Processing runs in your browser, so it is bound by available memory. Files up to a few megabytes format almost instantly; for much larger documents, close other tabs or split the file before formatting.