XML Formatter: Beautify and Indent XML Documents Online
Pretty-print minified or poorly indented XML documents with consistent indentation and line breaks. Instant browser-based formatting with no server upload required.
Try the free online tool
Runs entirely in your browser — no signup, no uploads.
XML is the backbone of countless data exchange formats, configuration files, and web services. SOAP APIs, Android layout files, Maven POM files, Ant build scripts, Office Open XML documents, SVG graphics, and RSS feeds are all XML under the hood. However, XML generated by machines or transmitted over networks is often minified into a single unreadable line, or formatted inconsistently with mixed indentation depths and style.
Formatting XML consistently makes the document dramatically easier to read, review, and debug. When attributes, child elements, and text nodes are each on their own line with proper indentation that reflects the document hierarchy, the structure of the data becomes immediately apparent. Finding a specific element, comparing two versions of a document, or understanding deeply nested configurations is far easier with well-formatted XML.
This tool takes any well-formed XML input and re-outputs it with clean, consistent indentation. You can choose between 2-space, 4-space, or tab indentation. The output is ready to paste into a code editor, commit to version control, or share with a colleague.
What Is XML Formatting and Pretty-Printing?
XML parsers are whitespace-agnostic for the most part: two XML documents that differ only in whitespace between elements are semantically equivalent. This means software can transmit XML as a single concatenated line to save bytes, and the receiving parser will interpret it identically to a fully indented version. However, human readers cannot.
Pretty-printing is the process of inserting line breaks and indentation to make the hierarchical tree structure of an XML document visible to the eye. Each nested element is indented one additional level relative to its parent, attributes can be placed on their own lines for readability, and the overall result mirrors the logical structure of the data.
Consistent formatting is also important for version control. When an XML file is reformatted, every line changes, making git diff output noisy. By standardizing on a single formatter and indentation style for a project, teams can minimize meaningless formatting diffs and focus on actual content changes.
How to Use This Tool
Follow these steps to format your XML document:
- 1
Paste your XML
Copy minified or inconsistently indented XML into the input panel. The tool accepts any well-formed XML document regardless of its current formatting state.
- 2
Choose indentation style
Select 2 spaces, 4 spaces, or a tab character as the indentation unit. Most code style guides for XML use 2 or 4 spaces; tabs are common in some editor configurations.
- 3
Set attribute formatting
Choose whether to keep all attributes on the opening tag line or to place each attribute on its own indented line. Attribute-per-line mode makes long element tags more readable but increases file length.
- 4
Click Format
The formatter parses the XML and re-serializes it with the chosen indentation and line break settings. Any parse errors are displayed with the line number and a description of the problem.
- 5
Copy or download the result
Use the Copy button to place the formatted XML on your clipboard, or click Download to save a .xml file. A minify button is also available if you need the opposite: compact, whitespace-free output.
Common Use Cases
XML formatting is useful across many development and data workflows:
- Beautifying SOAP API request and response payloads for debugging and documentation
- Formatting Android layout XML files, AndroidManifest.xml, and Gradle resource files for readability
- Pretty-printing Maven pom.xml, Spring configuration files, and other Java project XML
- Formatting SVG files exported from Inkscape or Illustrator to make them editable by hand
- Making RSS and Atom feed XML human-readable for inspection and troubleshooting
Tips and Best Practices
Get the most out of XML formatting with these tips:
- Run the XML validator first if you are unsure whether your input is well-formed. The formatter requires valid XML and will show parse errors for malformed input rather than producing garbled output.
- For XML that will be stored in version control, agree on a consistent indentation style for the project and configure your editor to use the same formatter settings so diffs stay clean.
- Be aware that formatting changes whitespace-only text nodes. If your application relies on preserving exact whitespace within elements for display purposes (such as pre-formatted content), review the formatted output carefully.
- When formatting very large XML files (several megabytes), consider using a command-line tool like xmllint for better performance: xmllint --format input.xml > output.xml.
- Use the attribute-per-line option for XML with many attributes per element (such as SVG paths or WSDL definitions) to make individual attributes easier to identify and edit.
Frequently Asked Questions
Does formatting change the meaning of the XML document?
For element-only content, no. Adding or removing whitespace between elements does not change the document's meaning to an XML parser. However, for mixed content (elements that contain both text and child elements), added whitespace technically creates new text nodes. Most applications ignore insignificant whitespace, but be aware of this distinction.
Can the formatter handle XML with a namespace declaration?
Yes. Namespace declarations (xmlns attributes) are treated as regular attributes and preserved exactly. The formatter does not modify namespace prefixes or URIs.
What happens if my XML contains a DOCTYPE declaration or processing instructions?
DOCTYPE declarations, processing instructions (<?...?>), and XML comments (<!-- -->) are all preserved in the formatted output. They appear on their own lines with appropriate indentation.
Can I format HTML with this tool?
Only if your HTML is valid XHTML (XML-serialized HTML). Regular HTML5 documents are not valid XML (for example, self-closing tags like <br> are not allowed in XML). Use an HTML formatter for regular HTML content.
How do I format XML in VS Code instead of using this tool?
Install the 'XML' extension by Red Hat (vscode-xml) and configure your indentation settings in .editorconfig or your VS Code workspace settings. You can then format XML files with the standard Shift+Alt+F shortcut.
Does the formatter support UTF-8 characters and Unicode?
Yes. The tool handles Unicode text in element content and attribute values. Make sure your XML declaration specifies the correct encoding (<?xml version="1.0" encoding="UTF-8"?>) if your file contains non-ASCII characters.
Ready to use this tool?
Free, instant, no account required. Runs entirely in your browser.