XML Formatter

Format, beautify or minify XML. It runs entirely in your browser, so your XML is never uploaded.

The formatter runs entirely in your browser and needs JavaScript. Everything else on this page works without it. Alternatives: xmllint --format file.xml in a terminal, or "Format Document" in VS Code with an XML extension installed.

Paste XML, drop a file or load the example. Files are read in your browser: nothing is uploaded. Press Ctrl+Enter to format.

Result

Formatted XML with line numbers. Copy it or download it.

The formatted XML will appear here.

Did this tool help? Support XMLNest

How do I format XML online?

Paste your XML into the input box, open a file with Open file… or drop one onto the tool. Then press Format, or Ctrl+Enter (⌘+Enter on a Mac). The result appears with line numbers and colors, ready to copy or to download as a UTF-8 file.

The Indent menu sets each level to 2 spaces, 4 spaces or a tab. Change it after formatting and the result is redone with the new indentation. Files up to 20 MB work, and the page stays responsive.

What does "pretty print" or "beautify" XML mean?

Both terms mean formatting: tags start on their own lines, indented by their depth, so the structure is easy to follow. XML from an API, a feed or an export often arrives on a single line. The pretty-printed version is easier to read, review and compare, and it holds the same elements, attributes and text.

Format or minify XML: which one do I need?

Format when a person has to read or edit the file. Minify when a program reads it and size matters, for example before sending it over a network. Minify removes the line breaks and indentation between tags and the extra spaces inside tags, and keeps everything else, comments included. The status line tells you how much smaller the result is.

Does this XML formatter upload my file?

No. The formatter runs in this browser tab. Your file is read on your device, and the security rules of this page stop it from sending anything. Nothing is saved: close the tab and it is gone. The privacy policy explains the rest. For JSON, use the XML to JSON converter; for stylesheets, the XSLT tester; for queries, the XPath tester.

Why does my XML show an error?

Before it formats anything, the tool checks that the XML is well-formed: one root element, every tag closed in the right order, attribute values in quotes, and characters such as & written as &. At the first broken rule it stops and gives the line and column. Go to line selects that line in the input, so you can fix it and press Format again.

Well-formed does not mean valid. A valid file also follows a DTD or XSD schema, and this tool does not check schemas. To only check it, use the XML validator, or the sitemap checker for a sitemap.

Questions

How can I convert XML to a readable format?

Paste it into the formatter on this page and press Format. Tags go on their own lines, indented by depth, except inside elements that hold text. Your XML never leaves your browser.

Can I format XML without a website?

Yes. In a terminal, xmllint --format file.xml prints the file indented, and most code editors can do it with an XML extension.

Is there a file size limit?

Yes, 20 MB for an opened file or for pasted text.

Does formatting change my data?

It changes the line breaks and indentation between the tags of elements that contain no text. Line endings become LF and the encoding declaration, if any, says UTF-8. Text, attributes, comments and CDATA sections are copied exactly. An XML parser may read that whitespace as text, so xml:space="preserve" on an element keeps it untouched.

Can it fix invalid XML?

No. It shows the line and column of the first error, so you can fix it. Well-formed is not the same as valid: valid XML also matches a DTD or XSD schema, which this tool does not check.

Can I format XML directly in Chrome?

Chrome shows an XML file that has no stylesheet as a tree, but it cannot change the indentation or minify the file. XMLNest, an extension available on the Chrome Web Store, shows XML files formatted, with line numbers.