How to Format XML as Beautified or Minified Text
Enter XML text, choose beautify for readable indentation or minify for compact output, and set a width when needed. Non-empty text is parsed or validated, so malformed XML can produce an unsuccessful result.
Choose the right XML layout
XML formatting changes the presentation of XML text so its hierarchy is easier to inspect or its layout is more compact. Choose beautify when line breaks and indentation will help you review elements, attributes, and nested content. Choose minify when you need compact text and accept that comments and whitespace between tags will be removed. The formatter also lets you set the indentation width used for readable output.
Format the XML step by step
-
Prepare the XML as text and decide what you need to see afterward. A non-string value cannot be processed successfully. Empty or whitespace-only text is treated separately and returns empty output, so provide a document containing XML when you want a formatted structure.
-
Select beautify for a readable layout. It is the default when no truthy mode selects minify. This choice is useful for checking nesting, matching elements, and following the relationship between parent and child nodes.
-
Select minify when compact text is more useful than visual spacing. For non-empty input, this mode validates the XML before processing it. It removes comments, collapses whitespace between tags, and trims whitespace at the beginning and end of the text.
-
Set the indentation width for beautified output when the default does not suit your review. The default is 2 spaces. For non-empty text, a value below 0, above 8, or not convertible to an integer falls back to 2, so choose a value within that range for a predictable custom layout.
-
Run the formatter and examine whether the operation succeeded. Beautify parses the XML before producing formatted text, while minify validates non-empty XML before compacting it. If processing fails, inspect the value type and document structure before changing presentation settings.
-
Check the size of a large source before submitting it. Non-empty input above 1,000,000 UTF-8 bytes is rejected. Whitespace-only input returns earlier, before this size check, which is why the size boundary applies to text containing at least one non-whitespace character.
Understand the formatted result
Interpret the result according to the mode you selected. A successful beautify result should present XML text with readable line breaks and indentation based on the selected width. A successful minify result should present a more compact form after the documented comment and whitespace changes. The two outputs may look very different while representing the same element arrangement.
An unsuccessful result means formatted output was not produced for that input. Malformed XML can fail because beautify parses before formatting and minify validates before compacting. A value supplied in a type other than text can also fail, as can non-empty input beyond the size boundary. Changing the indentation width does not correct an XML structure problem.
Treat an empty successful result differently from a formatted document. Empty or whitespace-only input produces no XML structure to review. For compact output, confirm that removing comments and spacing between tags is suitable for the next use, particularly when those parts were helpful during inspection. If they need to remain visible, use beautify instead.
Worked example
A developer receives a compact catalog fragment and wants its element nesting to be easier to inspect.
Enter <catalog><item id="7">Book</item></catalog>, choose beautify, set indentation to 4 spaces, and run the formatter.
The successful beautify result is readable XML with the item nested under the catalog and arranged using 4-space indentation.
Limitations
- Non-empty input must be text that passes XML processing and is no larger than 1,000,000 UTF-8 bytes.
Common errors
- A mismatched closing tag can make processing unsuccessful; correct the element nesting and submit the XML text again.
FAQ
Can I minify XML instead of beautifying it?
Choose minify when compact non-empty XML suits your next task. The mode validates the document, removes comments, collapses whitespace between tags, and trims surrounding whitespace.
What indentation width can I use?
For non-empty text, the default width is 2 spaces. A value below 0, above 8, or not convertible to an integer falls back to 2.
Why did formatting fail or return empty output?
If the value is empty or contains only whitespace, empty output is successful. With non-empty text, malformed XML, a non-string value, or a size above 1,000,000 UTF-8 bytes can lead to an unsuccessful result.