XML Formatter

Use the xml formatter tool online for quick developer workflows. Add examples, caveats, and avoid pasting sensitive secrets.

Free online file converter tool. Works in Chrome Firefox Safari Edge Opera and other modern browsers on Windows macOS Linux Android and iOS. No software installation required. Browser-side processing keeps your file local when supported. Completely free to use with no account needed.

XML Formatter

Format, pretty-print, or minify XML code instantly in your browser.

XML Formatter Features

Fast, private XML formatting directly in your browser.

Format & Minify

Switch between pretty-print and minify modes to expand or compress your XML.

Syntax Validation

Detects XML errors immediately and shows a clear error message.

Browser-Side When Supported

Your XML stays on your device. Privacy-aware, no sign-up needed.

How to Format or Minify XML

  1. 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.

  2. 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.

  3. 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.

AspectFormat (pretty-print)Minify
Line breaksOne element per lineRemoved
Indentation2 spaces, 4 spaces, or TabNone
Output sizeLarger, more readableSmallest possible
Best forDebugging, code review, editing by handAPI payloads, storage, data transfer
Whitespace between tagsAdded to show hierarchyStripped between tags
Data and structureUnchangedUnchanged

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.

References

  1. Extensible Markup Language (XML) 1.0 - W3C
  2. XML introduction - MDN Web Docs, Mozilla
  3. Pretty-printing - overview
  4. DOMParser - MDN Web Docs, Mozilla
  5. Namespaces in XML - W3C
  6. Clipboard.writeText() - MDN Web Docs, Mozilla
  7. XMLSerializer - MDN Web Docs, Mozilla
  8. Blob - MDN Web Docs, Mozilla