XML Formatter

Format and prettify XML instantly. Configurable indentation (2 spaces, 4 spaces, tabs). Validates well-formedness as it formats. 100% client-side.

100% private · runs locally

Paste minified or poorly indented XML and get back clean, consistently formatted output. The formatter uses the native browser DOMParser API to validate and parse the XML, then serializes it with your chosen indentation style. If the XML is malformed, the error is shown inline.

XML input
Formatted output XML

Related tools

Frequently asked questions

What is XML formatting?

XML formatting (or prettifying) adds consistent indentation and line breaks to XML markup, making it human-readable. Minified or single-line XML is valid but hard to read. Formatted XML shows the hierarchy clearly without changing the data.

Does formatting change the XML data?

No. Formatting only changes whitespace between elements. Text node content, attribute values, and structure are preserved exactly. The formatted XML is semantically identical to the input — a parser will produce the same document tree.

What XML features are supported?

The formatter handles elements, attributes, text nodes, CDATA sections, processing instructions, and XML declarations. It uses the browser's built-in DOMParser which supports all well-formed XML 1.0, including namespaces.

What's the difference between XML and HTML formatting?

XML is strictly parsed — all tags must be closed, attribute values quoted, and special characters escaped. HTML has a more lenient parser that handles unclosed tags and optional quotes. This tool only formats well-formed XML, not HTML.

Which indentation should I use?

2 spaces is the most common in modern web tooling (JavaScript, JSON). 4 spaces is traditional in Java and .NET XML tools. Tabs allow each developer to view with their preferred tab width. All three produce semantically identical XML — it's a style choice.