Skip to main content

XML formatter

Reindent XML for easier reading, minify it for a more compact result, and detect syntax errors before reusing the generated document.

  • Clipboard
  • Export
Automate

Embed this widget

Customize the result, check the live preview, then copy the code.

Preview

Embed code type

Code to copy

Responsive and automatically resized by Bethemesh.

Indentation size

Was this tool useful?

How does this tool work?

Format an XML document to inspect its elements and nesting, or reduce presentation whitespace with compact mode. Parsing and serialization take place in your browser without uploading the document for processing. The formatter prioritizes meaningful text. Less uniform indentation can therefore be intentional, particularly in paragraphs mixing text and elements or in blocks that explicitly preserve whitespace.

Parsing requires well-formed XML with one root element, correctly quoted attributes and closed tags. DOCTYPE declarations are rejected, so documents depending on a DTD or its entities are unsupported. Standard references such as & are interpreted by the parser and escaped again during serialization. The formatter does not load an XSD or validate business rules.

Indentation inserts line breaks between elements only where the subtree can be rearranged without changing its text. Mixed content, CDATA, spaces between inline elements and xml:space="preserve" subtrees are left unindented. A single space between elements can matter; removing it just to shorten the output would change the content. Compact mode is deliberately conservative for that reason.

Serialization can normalize spellings such as attribute quotes, entity references or empty-element endings. Byte-for-byte preservation is not promised. An initial XML declaration is retained, and the formatter does not intentionally remove comments or processing instructions. Before replacing a signed document, check the signature procedure and required canonical representation.

How to use this tool

  1. Provide a complete document

    Paste or import XML with its root element. Documents relying on a DTD are outside the supported input.

  2. Choose the presentation

    Select indentation and Format, or use compact mode. A preserved subtree can stay on one line regardless of the chosen layout.

  3. Review and export

    Check important text, spaces and attributes before copying or downloading the XML. Keep the source if another application needs its exact representation.

Use cases

Read a service response

Indent an element-based document to locate nested groups. A rejected document needs a syntax correction before indentation settings can help.

Inspect marked-up prose

Check a paragraph containing emphasis with surrounding text. Preserving inline spaces prevents words from being joined by formatting.

Prepare a comparison

Apply the same presentation to two small sources before a text diff. This output is not XML canonicalization for signature processing.

Examples

Indent simple elements

Two spaces separate each level. This document has no mixed text, so its child elements can be placed on separate lines.

Input

<root><a>1</a><b>2</b></root>

Result

<root>
  <a>1</a>
  <b>2</b>
</root>

Keep a mixed paragraph intact

Text and spaces around b remain in place. Compact mode does not remove these separators needed to read the paragraph.

Input

<p>Hello <b>A&amp;B</b> world</p>

Result

<p>Hello <b>A&amp;B</b> world</p>

Tips and best practices

  • An XML error may come from an unescaped & or mismatched letter case in tags. Correct the structure before formatting.
  • Well-formed XML does not necessarily satisfy a schema. XSD validation and signature verification remain separate steps.
  • Use the HTML formatter for HTML; HTML browser tolerance for omitted tags does not apply to XML documents.

Sources and references

Frequently asked questions

Why are some elements not indented?

Their subtree contains mixed text, CDATA, inline spaces or xml:space="preserve". Keeping the content intact takes precedence over visual uniformity.

Does compact mode remove every space?

No. It only removes presentation whitespace the engine can safely rearrange. Meaningful text spaces and preserved subtrees remain intact.

Are DTDs or custom entities accepted?

No. DOCTYPE is rejected rather than silently ignoring a dependency that can affect meaning. Use an appropriate XML processor when the format requires a DTD.

Can I safely reformat signed XML?

Do not assume its signature will remain valid. Serialization may change the representation; check your system’s canonicalization and verification requirements.

Related tools

Tools similar or complementary to this one.

Similar tools

Test an XPath expression against XML and immediately inspect the matching results.

DevelopmentUse this tool

Compare two texts line by line and quickly spot additions, deletions and changes.

DevelopmentFeaturedUse this tool