XML Formatter and Minifier

Paste XML to indent it or to strip the whitespace between tags. Attributes, comments, CDATA sections and the declaration come back unchanged, and tag errors are reported with line and column.

Runs locally in your browser

Indenting and compressing keep the same data

The formatter only adds or removes whitespace between tags; attribute values, comments, CDATA sections, the declaration, DOCTYPE and processing instructions are written back byte for byte. Compression keeps comments, and a subtree marked xml:space="preserve" is left alone by both buttons.

How to format or minify XML

Indent pasted XML so it can be read, or strip the whitespace between tags to make the document compact. The layout is rebuilt from a single scan of the input: attributes, comments, CDATA sections, the XML declaration, DOCTYPE and processing instructions are written back unchanged.

The scan runs in this tab, so nothing is uploaded and the page keeps working with the network disconnected. Tag nesting is checked while the document is read; this is not a validation against a DTD or an XML Schema.

  1. Paste the XML into the field above. Indentation and line breaks in the input do not matter; the tool rebuilds the layout from the structure.
  2. Press XML Formatting to indent each nesting level with four spaces, or XML compression to remove the whitespace between tags and return the document on as few lines as possible.
  3. Read the message under the buttons. A mismatched or unclosed tag, a second root element, text outside the root, a bare “<” in text or in an attribute value, an unquoted attribute value, and an unterminated comment, CDATA section or tag are each reported with their line and column.
  4. Press Copy for the result; the button copies the formatted output and falls back to the input when no result exists yet. Clear empties the input together with the result.

What the formatter changes and what it leaves alone

What the formatting pass changes

Indentation is the only thing it adds: four spaces per level, and an element whose content is text only stays on one line. Mixed content is never rearranged, so <p>Hello <b>world</b> !</p> keeps its spaces and comes back exactly as it was written.

Attribute values, comments, CDATA sections, the declaration, DOCTYPE and processing instructions are copied byte for byte, and attribute order is preserved. The one exception is an unquoted value such as class=x, which is written back as class="x" and reported, because XML requires the quotes.

What the compression pass removes

Compression drops whitespace-only text between markup at every level, so an indented document becomes one compact line. Text content is not touched: <a> spaced text </a> and mixed content keep their spaces, and an element whose whole content is whitespace keeps it as well.

Comments survive compression; delete them yourself if the bytes matter. A subtree marked xml:space="preserve" is left untouched by both buttons.

When the document is not well formed

Problems are reported by position, for example “Line 1, column 10: </b> closes <a> instead.”, “Line 1, column 7: <a> is never closed.” or “Line 1, column 1: </x> has no matching start tag.”. The layout is still printed so you can see what the tool made of the input, but the reported position is what to fix first.

If the input holds no element at all — plain text, or only whitespace — the tool says so instead of printing a guess. Only the first five problems are listed, with a count of the rest.

Size, speed and limits

A 600 KB document with 20,000 elements is laid out in roughly 0.15 seconds in Chrome, and output longer than 200,000 characters is printed without syntax colouring so the tab stays responsive. The practical ceiling is the memory of your own device.

The check is structural only: the tool does not validate against a DTD or XML Schema, does not resolve entities or download external files, and does not report whether namespace prefixes are declared. Indent size is fixed at four spaces.

Recent tools: