❯
❯
XML
Code Formatting
Formatter Tool

XML Formatter

Beautify, minify and validate XML online, free and private.

Paste messy or minified XML and turn it into clean, indented code in one click. Choose 2 spaces, 4 spaces or tabs, put each attribute on its own line and turn empty tags into self-closing ones. Need the opposite? Minify your XML to make it smaller, or click Validate to check that every tag is closed and nested correctly. Your code is formatted in your browser and never uploaded. The tool is free, with no sign-up.

100% Free

No Sign-Up, No Install

Beautify & Minify

Plus a Well-Formed Check

Private & Secure

XML Never Leaves Your Browser

Your Code Style

2 Spaces, 4 Spaces or Tabs

0 characters 0 lines 0 B
Result
0 B 0 lines
Settings
Indentation
XML options
Minify

Tip: press Ctrl + Enter inside the input box to beautify. You can also drop a file onto the input.

Private by design: your code is formatted in your browser and never uploaded. Protected by Cloudflare Turnstile.

How Do You Format XML Online?

To format XML online, paste your code into the XML input box or click Upload to open an .xml file, choose your indentation and options under Settings, then click Beautify XML. The clean, indented code appears in the Result box, ready to Copy or Download. Click Minify XML for a compact version instead, or Validate to check that your XML is well-formed.

XML is often hard to read: returned on a single line by an API, exported from a database or CMS, or generated by a tool with no line breaks at all. An XML formatter, also called an XML beautifier, pretty printer or XML viewer, gives every element and attribute a consistent, indented layout so you can see the tree structure, find the value you need and spot mistakes quickly. An XML minifier does the reverse, removing whitespace and comments so the file is smaller to store or send.

Everything happens on your own device. Beautify, Minify and Validate run on Teasoft’s own lightweight code in your browser, so the formatter works even on large API responses without a round trip to a server. Your XML is not sent to Teasoft or anyone else, so you can safely format API responses, configuration files, sitemaps and feeds that contain private data.

What changes in your XML:

Part of your XMLWhen you beautifyWhen you minify
Indentation and line breaksRebuilt with 2 spaces, 4 spaces or a tab for each nesting level.Removed between tags, so the document fits on one line.
Elements and attributesOne element per line, and each attribute on its own line if you choose.Kept, with extra spaces between attributes removed.
Empty elementsKept as <a></a>, or turned into <a/> if you choose.Same choice as when you beautify.
CommentsKept where they are.Removed when Remove comments when minifying is ticked. Untick it to keep them.
XML declaration, CDATA and processing instructionsKept exactly as written.Kept exactly as written.
Element names, attribute values and textUnchanged.Unchanged.

Common reasons to format XML

What each control does:

ControlWhat it doesWhen to use it
XML input boxHolds the XML you want to formatPaste or type code, or drop an .xml, .svg, .xsd, .xsl, .xslt, .rss or .txt file onto it.
Upload, Paste, Sample and ClearOpens a file, pastes from the clipboard, loads an example or empties the boxClick Sample to try the tool before using your own XML.
IndentationSets 2 spaces, 4 spaces or a tab for each nesting levelMatch the code style of your project or team.
End with a new lineAdds a line break at the end of the resultKeep it on for files you save in Git or open in code editors.
Each attribute on its own linePlaces every attribute of an element on a separate lineSVG files, Android layouts and other elements with many attributes.
Turn <a></a> into <a/>Writes empty elements as self-closing tagsShorter, tidier output for empty elements.
Remove comments when minifyingStrips <!– comments –> from minified XMLLeave it ticked for the smallest file. Untick it to keep notes and licence text.
Beautify XML, Minify XML and ValidateFormats, compresses or checks your XMLBeautify to read, Minify to ship, Validate to find errors.
Copy, Download and Use as inputCopies the result, saves it as a file or moves it back into the input boxUse as input to run another step, such as Validate and then Minify.

Good to know

What You Can Do With This Tool

How to Format XML (3 Steps)

Add your XML

Paste your code into the XML input box, drop a file onto it or click Upload. Click Sample to try an example first.

Choose your settings

Pick 2 spaces, 4 spaces or tabs, and decide whether to put attributes on their own lines and self-close empty tags.

Beautify, then copy or download

Click Beautify XML or press Ctrl + Enter. Copy the clean result or Download it as an .xml file.

Tip: if Beautify shows an error, click Validate to see where your XML breaks. The most common causes are a missing closing tag, an end tag that does not match its start tag, an unquoted attribute value and a bare & that should be written as &amp;. Working with an API that returns JSON instead? Use the JSON Formatter.

Which Option Should I Use?

TaskUseWhy
Read an API response or log that is on one lineBeautify XMLIndents every element so you can follow the tree.
Make a file smaller to send or storeMinify XMLStrips whitespace, and comments if ticked, without changing the data.
Find out why a file will not loadValidatePoints to the unclosed, mismatched or badly quoted tag.
Review elements with many attributesEach attribute on its own lineMakes long tags, such as SVG paths or Android views, easy to scan.
Tidy empty elementsTurn <a></a> into <a/>Gives shorter, consistent output.
Match your project’s code styleIndentation: 2 spaces, 4 spaces or TabKeeps Git diffs small and reviews clean.
Run another step on the resultUse as inputBeautify, check, then minify without copying and pasting.

Getting better results when you format XML

After you format your XML

  • Check the result. Compare it with the original if whitespace inside text matters to your app.
  • Minify for production. Click Use as input, then Minify XML to get a compact copy to deploy.
  • Keep your style consistent. Use the same indentation for every file in a project so Git diffs stay small.
  • Format related files. Use the JSON Formatter for API data and the HTML Formatter for web pages.

Frequently Asked Questions

Paste your XML into the XML input box or click Upload, choose your indentation under Settings, then click Beautify XML. Copy or download the clean result from the Result box.

Yes. It is completely free, with no sign-up and no limit on how often you use it.

No. Your XML is formatted, minified and validated inside your browser on your own device. It is never sent to Teasoft or anyone else.

Beautify adds line breaks and indentation so XML is easy to read. Minify removes them, and comments if you choose, so the file is as small as possible. Both keep your data the same.

Yes. Paste the minified XML and click Beautify XML. The tool rebuilds the indentation from the tag structure. Comments that were removed earlier cannot be brought back.

No. Element names, attributes, values, text, CDATA and processing instructions stay the same. Only the whitespace between tags changes, so parsers read the file the same way.

It checks that your XML is well-formed: one root element, every start tag closed by a matching end tag, correct nesting, quoted attribute values and escaped special characters. It does not check your XML against an XSD schema or DTD.

Yes. Tick Each attribute on its own line under XML options. It is useful for SVG files, Android layouts and other elements with many attributes.

Yes. Choose Tab under Indentation, or pick 2 or 4 spaces to match your project.

Yes. Beautify keeps every comment where it is. Minify removes comments only when Remove comments when minifying is ticked.

Yes. They are all XML, so you can open .svg, .rss, .xsd, .xsl and .xslt files, as well as .xml and .txt, and format them the same way. Sitemaps and SOAP messages work too.

Your XML is not well-formed. Look for a missing or mismatched end tag, an unquoted attribute value, a bare & character or text before the <?xml?> declaration. Fix it and try again.

Click Download in the Result box to save it to your device as an .xml file, or click Copy to paste it straight into your code editor.

Yes. Namespace prefixes and xmlns declarations are kept exactly as written, so SOAP envelopes, XSLT stylesheets and Office XML stay valid.

Yes. It works in Chrome and Safari on Android and iPhone. Paste your XML or tap Upload to open a file from your phone.

No. Everything runs in your web browser. There is nothing to download or install, and no account is needed.

It works in Chrome, Edge, Firefox, Safari and other modern browsers on Windows, Mac, Linux, Android and iOS.

Yes. Press Ctrl + Enter inside the input box to beautify your XML straight away.

About Teasoft's XML Formatter

Teasoft's XML Formatter is a free online tool to beautify, minify and validate XML. It turns minified or messy XML into clean, indented code with 2 spaces, 4 spaces or tabs, can put each attribute on its own line and self-close empty elements, and checks that your document is well-formed before you use it.

It is made for anyone who works with XML: developers reading API responses and SOAP messages, SEO specialists checking sitemaps and RSS feeds, Android and Java developers tidying layouts and pom.xml files, designers cleaning up SVG code, and students learning how XML is structured.

Your XML is processed on your device and is never uploaded. A quick Cloudflare Turnstile check keeps the tool free from abuse, and there is nothing to install and no account to create.