Back to Developer
XML Formatter — pretty / minify XML in one click

XML Formatter — pretty / minify XML in one click

Format XML with two modes: pretty (indent 2/4/tabs, line breaks, aligned attributes) and minify (strip whitespace into a single line). Built on fast-xml-parser with a hand-rolled indenter. Preserves CDATA, comments, processing instructions (`<?xml ... ?>`), DOCTYPE, self-closing tags, attribute order, and XML namespaces (xmlns:foo). For XML ↔ JSON, use xml-json-convert. For HTML, use a dedicated HTML formatter — XML parsers reject unclosed tags like HTML's `<br>`. Runs entirely in your browser.

developerconversion

How to use

1) Pick a mode: Pretty (indent 2 / 4 / tab) or Minify. 2) Paste XML into the input field, or use the Sample button. 3) Press Run — fast-xml-parser parses your XML and rebuilds it in the chosen mode. Comments, CDATA, XML declarations, and DOCTYPE are preserved. 4) Copy the result. Output size is also shown.

FAQ

Can I format HTML with this?
Not in general. XML requires strict closing tags (`<br/>`); HTML allows void elements like `<br>` and `<img>`. This XML parser rejects unclosed tags as invalid. Use a dedicated HTML formatter (Prettier, js-beautify) for HTML. XHTML (XML-compliant HTML) works fine here.
Are comments / CDATA / XML declarations preserved?
Yes. fast-xml-parser's `commentPropName` / `cdataPropName` options keep comments (`<!-- ... -->`) and CDATA (`<![CDATA[ ... ]]>`) as distinct nodes that are written back during build. XML declarations (`<?xml version="1.0" ... ?>`) and DOCTYPE are extracted from the input header and re-attached to the output.
Is attribute order preserved?
Yes — fast-xml-parser stores attributes as a plain JS object, which preserves insertion order. The only edge case is when attribute names are purely numeric (`<el 1="a" 0="b"/>`), where JS reorders integer keys. Negligible in practice.
Are XML namespaces preserved?
Yes. `xmlns:foo` declarations are kept as regular attributes, and namespaced tags like `<foo:bar>` keep the prefix in the tag name. SOAP / XHTML / SVG namespaces all round-trip correctly.
Self-closing tags?
Empty elements are emitted as `<empty/>` (self-closing), not `<empty></empty>`. Controlled via `suppressEmptyNode: false`.
How large can the input be?
fast-xml-parser holds the parsed tree in memory, so any XML up to your browser's heap limit (~100 MB practical) works. Tens of MB takes 1-2 seconds. GB-scale logs need a server-side tool like xmlstarlet.
Does minify preserve CDATA whitespace?
Yes. CDATA sections are explicitly excluded from whitespace stripping — internal newlines / spaces / text are kept verbatim.
Is anything uploaded?
No. fast-xml-parser (MIT) runs as JavaScript inside your browser; XML you paste is never sent over the network.

Related tools