Skip to content

XML Formatter and Prettifier

Format, indent, and validate XML documents with customizable indentation and output options.

XML Formatter and Prettifier tool

Loading...

Example

Input: <note><to>Ada</to><body>Hi</body></note> then click Format XML

Result: <note> / <to>Ada</to> / <body>Hi</body> / </note> (child lines indented 2 spaces)

Each element starts on its own line and nesting adds one indent level. Elements that contain only text stay on one line, and comments and CDATA are kept.

  1. Paste your raw, minified, or poorly formatted XML into the input text area.
  2. Select the indentation style - choose between 2 spaces, 4 spaces, or tabs.
  3. Click "Format XML" - the formatter validates your XML first, reporting any well-formedness errors with line and column numbers.
  4. View the beautifully indented and structured XML output with proper nesting.
  5. Optionally click Minify to compact the XML instead of formatting it.
  6. Click the copy button to copy the formatted or minified XML to your clipboard.

Formatting and Validating XML

An XML formatter puts each element on its own line and indents it by nesting level, so a dense one-line document becomes easy to read. This one checks that the XML is well-formed first, and it can minify a document instead. Well-formed means the basic XML rules are followed. Every tag is closed, elements nest without overlapping, attribute values are quoted, and there is exactly one root element. If a rule is broken, the formatter stops. It shows the line and column of the problem rather than guessing at a fix. It does not check the document against a schema (XSD or DTD), which is a separate step.

Choose 2 spaces, 4 spaces or tabs and click Format XML. Elements that hold only a short piece of text stay on one line, such as <to>Ada</to>. Elements with children open and close on separate lines. The XML declaration, comments, CDATA sections, processing instructions and DOCTYPE lines are all kept. Text is trimmed as it moves onto its own line, so check the result where spaces inside mixed text matter.

Minify does the opposite. It removes the gaps between tags that hold only whitespace, giving a compact document while keeping text, comments and CDATA. To turn the XML into data for your code, use the XML to JSON Converter. For JSON documents, the JSON Formatter works the same way.

Sources

Frequently Asked Questions

Well-formed XML follows the grammar rules that every XML document must obey, such as closed tags and proper nesting. Valid XML is well-formed and also matches a schema that defines which elements and attributes are allowed. This tool checks well-formedness only. Use a schema validator with your XSD or DTD for the second check.
An XML document must have a single element that contains everything else. Two elements side by side at the top level, as in <a/><b/>, are not allowed. Wrap them in one parent element, such as <items>...</items>, and format again. Text outside the root element is not allowed either.
Element names, attributes, text, comments and CDATA are kept. What changes is whitespace. Line breaks and indentation between tags are replaced, and the text in each element is trimmed of leading and trailing spaces. If your XML depends on exact whitespace inside text, as some mixed-content documents do, compare before and after.
Yes. Click Minify to remove the whitespace-only text between tags, such as line breaks and indentation. Text content, comments and CDATA sections stay as they are. The document is validated first, just as with formatting, so errors are reported before anything changes.

Related Tools

JSON to XML Converter

Convert JSON data to well-formed XML documents with customizable root element and formatting options.

Developer Tools

XML to JSON Converter

Parse XML documents and convert to structured JSON, with attributes kept as @_-prefixed keys and well-formedness checks.

Developer Tools

JSON Formatter and Validator

Format, validate, beautify, and minify JSON data with a collapsible tree view and line-and-column error detection.

Developer Tools

YAML Formatter and Viewer

Format, validate, and visualize YAML documents with tree view and customizable indentation.

Developer Tools

HTML Minifier

Minify HTML by removing comments and collapsing whitespace between tags and inside tags to reduce document size.

Developer Tools

CSS Minifier

Minify CSS by removing whitespace, comments, and redundant code to reduce file size.

Developer Tools