XML Formatter

Paste messy XML and get clean, indented output in one click. Invalid XML shows a clear error, and you can minify it to one line.

Last updated: 17 November 2026.

Your formatted XML will appear here.

Format adds clean indentation. Minify shrinks it to one line. Invalid XML shows the exact problem instead of a blank result.

What XML is

XML stands for Extensible Markup Language, and it is a way of writing data so that both people and computers can read it. An XML file is made of tags, which are labels in angle brackets. Each tag marks a piece of data, and tags sit inside other tags to show how the pieces fit together. A simple note might look like a note tag holding a to tag, a from tag, and a message tag. The names of the tags are up to you, which is what makes XML extensible. A bookshop can use book and author tags, while a weather service can use city and temperature tags, and both files follow the same rules.

Why XML needs formatting

XML written by a program often comes out as one long line, or with messy spacing that makes it hard to read. The data is still correct, but a person opening the file sees a wall of tags and cannot tell where one section ends and the next begins. Formatting fixes that by putting each tag on its own line and indenting child tags under their parents. The structure becomes visible at a glance: you can see which tags sit inside which, and you can spot a missing closing tag far more easily. Formatting never changes the meaning of the data. It only changes the white space between the tags, which XML ignores in most cases.

How to use this formatter

Paste your XML into the box and press Format XML. The cleaned up version appears below, with each level of tags indented two spaces deeper than its parent. The box comes with a short sample already filled in, so you can press the button straight away and see the difference. Press Minify instead if you want the opposite: the whole document squeezed into a single line with no extra space, which is useful when a file has to be small or pasted into a place that does not allow line breaks. Press Copy output to take the result, and Clear to start over. If your XML has a mistake, the tool shows a clear error naming the problem. If your data is in JSON instead of XML, the JSON formatter does the same job for JSON, including pointing to the exact line of an error.

The rules of well formed XML

XML has a small set of strict rules, and a file that follows them is called well formed. Every opening tag needs a matching closing tag with the same name, spelled exactly the same way, including capital letters. Tags must nest properly, so if a tag opens inside another tag, it must close before the outer tag closes. Overlapping tags are not allowed. A file must have exactly one root tag that holds everything else, and attribute values must sit inside quotes. Special characters like the ampersand and the less than sign cannot appear raw in text, because the parser reads them as markup, so they are written as codes like & and < instead.

Formatting versus minifying

Formatting and minifying are opposite jobs, and each has its time. Format when a person needs to read the file, for example while you are writing it, checking it, or showing it to someone else. The extra line breaks and spaces cost a little size, but they save far more time in reading. Minify when a machine is the only reader, for example when the file travels over the internet or sits inside another file. The minified version is smaller and faster to send, and the machine does not care that it is hard to read. One common workflow is to minify a file for sending, then format it again when it comes back for checking. Before you share a long file with anyone, a quick length check helps too, and the word counter counts words and characters in any text you paste.

The XML declaration and comments

Many XML files start with a declaration line, like the version and encoding, which tells the reader how to interpret the file. This formatter keeps that line at the top and does not treat it as a normal tag. Comments are kept as well: a note between markers stays in place and is indented with the tags around it, so your explanations survive a format. Empty tags, which hold nothing, are written in the short self closing form, with a slash before the closing bracket. Attributes stay on the same line as their tag, so a tag with several settings still reads as one unit instead of scattering across lines.

Your XML stays on your device

This formatter runs fully in your browser with plain JavaScript. The XML you paste never leaves your device, nothing is uploaded to a server, and nothing is stored after you close the page. That matters, because XML often carries private detail: settings, customer records, and business data. Keeping the work on your own device means that detail stays yours. There is no account, no sign up, and no waiting. Paste, format, copy, and move on.

Frequently asked questions

What does the XML formatter do?

It takes messy XML and lays it out with clean indentation, so each tag sits on its own line and child tags sit under their parents. The data stays exactly the same, only the white space changes.

What is minify?

Minify squeezes the whole XML document into a single line with no extra spaces or line breaks. The result is smaller and faster to send, but harder for a person to read. Format it again any time to make it readable.

What if my XML has an error?

The tool shows a clear error that names the problem, often with a line and column number. Common causes are a tag that was never closed, a closing tag that spells the name differently, or two root tags instead of one.

Does formatting change my data?

No. Formatting only changes the white space between tags. The text inside tags and the attribute values stay exactly as they were, so the formatted file carries the same data as the original.

Is my XML sent anywhere?

No. Formatting and minifying run in your browser with plain JavaScript. The XML you paste never leaves your device, and nothing is stored.