HTML Prettier - Format, Beautify and Validate HTML Online
HTML rarely arrives tidy. It comes out of a bundler as one 40,000-character line, out of a CMS export with mixed tabs and spaces, out of view source on a live page, or out of three developers who each had different editor settings. This HTML formatter re-prints it as indented, correctly nested markup - or squeezes it back down in minify mode - entirely inside your browser tab.
The markup is tokenized into a node tree that records every tag, every attribute exactly as written and every source offset, and the beautified output is printed by Prettier's own HTML printer. Raw-text elements are consumed as opaque text, so a <div> living inside a JavaScript string never becomes an element - the single most common way a regular-expression beautifier destroys a page.
Whitespace is not decoration
Most of the difficulty in formatting HTML is deciding which whitespace a browser actually paints. A newline between two <div> elements renders as nothing; the same newline between two <span> elements renders as a space, which is why <a>one</a> <a>two</a> and the same pair with no gap look different on screen. The formatter follows each element's default CSS display to tell those cases apart, and it never re-spaces the inside of <pre>, <textarea> or an element carrying xml:space="preserve".
What it handles
The full modern grammar: the HTML5 doctype; void elements such as <br>, <img> and <meta>, with an HTML5 versus XHTML self-closing toggle; raw-text <script> and <style> blocks, whose contents are re-indented by the real JavaScript and CSS printers; boolean and data- attributes; comments, conditional comments and CDATA; character entities; custom elements and web components; and SVG and MathML, where camelCase names like viewBox and preserveAspectRatio are case-sensitive and are never re-cased.
Structure warnings and repair
Because the document is parsed rather than pattern-matched, the same pass that formats can also report what is wrong with it: tags that were never closed, tags closed by the wrong closer, stray end tags with nothing to close, duplicate id values with every line they appear on, nesting HTML forbids such as <li> outside a list, and accessibility gaps such as an <img> with no alt or an <html> with no lang. Repairs a browser would make anyway - discarding a stray closer, writing in a missing </script> - are applied and listed, never applied silently.
Templates, minification and diffs
<?php … ?> and <% … %> islands are lifted out before printing and restored untouched, since an HTML parser would end them at the first >. Minify mode removes only the whitespace a browser would not paint, drops comments while keeping IE conditional ones, collapses disabled="disabled" to disabled and can strip optional attribute quotes, reporting the bytes saved. Check-only mode shows a line-by-line diff instead of replacing your input.
Private by construction
Nothing is uploaded, nothing is logged, and no network request is made after the page loads - so markup carrying an API key in a data attribute, a customer name in a table or an unreleased headline stays on your machine. Files up to 2 MB can be dropped straight onto the editor.