XML & HTML Formatter

[ FORMATTED ]
<article class="post"> <h1> Title </h1> <p> Some <em> markup </em> with a <br> break. </p> <pre> indented code stays</pre> <ul> <li> one </li> <li> two </li> </ul> <!-- a comment --> </article>
16 tags · 0 problems
Tags16
Problems0
Characters276
This formats; it does not validate. Well-formedness against the full specification — entities, namespaces, doctypes — is a larger claim than indenting a document supports. The structural faults below are the ones it genuinely detects.
The contents of pre, textarea, script and style were left exactly as they were. Whitespace is part of the content there — re-indenting a pre block destroys a code sample, and a textarea gains leading spaces in its value.
Void elements such as br, img and input have no closing tag and are not indented into. Treating one as an opening tag pushes everything after it one level deeper for the rest of the document, which is the commonest way a hand-written formatter goes wrong.
[ WHAT THIS IS ]

It formats; it does not validate, and the page says so. Reporting "valid" because a document could be indented is telling you something the tool does not know.

Some elements have whitespace as content: pre, textarea, script and style. Re-indenting inside a pre destroys the code sample; a textarea gains leading spaces in its value. Those four are left untouched.

Void elements have no closing tag. Treat <br> as an opening one and everything after it indents one level deeper for ever — the most visible way a hand-written formatter fails.

And it does not parse to a tree. A tree round trip drops comments, CDATA and unusual doctypes. This is a token stream: everything that goes in comes out.

[ QUESTIONS ]

Does this validate my XML or HTML?

No, and it says so on the page. Validating means checking against the whole specification — entities, DTDs, namespaces, encoding declarations — and a tool that reports “valid” because it managed to indent a document has told you something it does not know. What it does report is the one class of fault it genuinely detects: a tag that never closes, and a closing tag that matches nothing.

Why is my <pre> block left alone?

Because whitespace inside it is content, not formatting. Re-indenting a pre block destroys the code sample it contains, and a textarea treated the same way gains leading spaces in its value. Script and style are left alone for the same reason. Those four elements are passed through exactly as they arrived.

Why do some formatters indent everything after a <br> one level deeper?

Because they treat it as an opening tag. Void elements — br, img, input, hr, meta, link and the rest — have no closing tag in HTML, so nothing ever brings the indent back out, and the rest of the document drifts right for ever. It is the single most visible way a hand-written formatter fails, and this one knows the list.

Will it lose my comments or doctype?

No. It does not parse to a tree and re-emit, which is what drops anything the parser did not model — comments, processing instructions, CDATA, an unusual doctype. This works on a token stream: every token that goes in comes out, and only the whitespace between them changes. A formatter that silently deletes part of a document is far worse than one that leaves it oddly indented.

Why does it still produce output for a broken document?

Because refusing is no use to somebody trying to see where it broke. The problems are listed and the formatted output is produced anyway, so you can look at the structure and find the missing tag. An unmatched closing tag is also deliberately not allowed to change the indent level — otherwise one mistake pulls every following line left and the whole document looks wrong.

Is my markup sent anywhere?

No. Everything happens in your browser and nothing is transmitted or stored.

[ THE MATHS ]
What is left untouched
pre, textareawhitespace is content
script, styleanother language inside
<!-- comment -->kept whole
<!DOCTYPE>, CDATAkept whole
[ THE VOID ELEMENTS ]

area, base, br, col, embed, hr, img, input, link, meta, param, source, track, wbr have no closing tag. Nothing brings the indent back out once one is entered, so the whole rest of the document drifts right.

[ NEXT ]
56HTML Tag RemoverWhen you want the text without the markup
43JSON FormatterThe other format that needs tidying
48Text ComparisonCheck formatting changed nothing else
64JSON DiffCompare data rather than text
[ IMPORTANT ]

Runs entirely in your browser. This formats rather than validates — well-formedness against the full specification is a larger claim than indenting supports. It reports the structural faults it genuinely detects and still produces output for a broken document. Nothing you type here is sent to our servers — the calculation runs entirely in your browser.