XML Formatter
Paste XML to format it with 2-space, 4-space, or tab indentation, or minify it to a single line. Uses the browser's built-in XML parser for accurate error detection. No data leaves your browser.
Pretty-print or minify XML directly in the browser. The formatter parses the document as XML, validates it, and can output indented markup using 2 spaces, 4 spaces, or tabs, while the minifier removes whitespace between tags after serialization.
How to format or minify XML
- Paste XML into the input area.
- Choose the indentation style when formatting.
- Click Format to pretty-print the document or Minify to compact it.
- Review any parse error shown by the browser XML parser.
- Copy the output when the result is ready.
Parsing and serialization behavior
Formatting uses DOMParser with the application/xml MIME type, then recursively serializes document, element, text, and comment nodes. Text is trimmed and escaped, empty elements can become self-closing tags, and attributes are emitted in their parsed order.
Minifying parses the XML first, serializes it with XMLSerializer, removes whitespace between adjacent tags, and trims the result. Because the formatter rebuilds the parsed tree rather than preserving the source byte-for-byte, insignificant whitespace and some source-level formatting details may change.
Privacy and limitations
XML parsing and formatting run locally in the browser and the input is not intentionally uploaded for processing. Behavior follows the browser DOMParser and XMLSerializer implementations. This tool is intended for normal XML structure cleanup and validation, not for preserving every lexical detail such as original whitespace, entity spelling, or processing-instruction formatting exactly as typed.
Frequently asked questions
Does the tool validate XML syntax?
Yes. Invalid XML produces a parser error instead of formatted output.
Can I use tabs for indentation?
Yes. The formatter supports 2 spaces, 4 spaces, or a tab.
Does minify remove all text whitespace?
No. It removes whitespace between tags after XML serialization, while text content remains part of the parsed document.
Will the output be byte-for-byte identical to the input?
No. Parsing and re-serialization can normalize source formatting details.
Are comments preserved?
Comments are explicitly serialized in formatted output.