Skip to content

HTML Formatter & Beautifier

Paste minified or messy HTML and get it back with proper indentation, line breaks between block elements, and consistent tag casing. The reverse direction — minifying for production — is one toggle away. Works on full documents, fragments, JSX-like markup, and templating syntax from Handlebars, Twig, or ERB.

Why HTML Formatting Matters

Browsers don't care about whitespace inside HTML, but humans do. A minified bundle pulled out of a CDN, a server-rendered fragment from a framework, or a chunk of inherited code copy-pasted from a CMS will routinely arrive as one long line with no breaks. Reading that requires either an editor with format-on-paste or a tool that fixes it in place. Formatting also makes diffs sane — see the text diff tool for what an unformatted vs formatted diff looks like.

Beyond readability, consistent formatting catches real bugs. Mismatched tags, accidentally-nested forms, and unclosed elements all surface visually once the indentation is correct. The formatter doesn't fix invalid HTML, but it surfaces it: indentation gets weird in exactly the spot where the parser had to guess.

How It Works

The HTML is tokenized into tags, attributes, text nodes, and comments. Block-level elements (

,
,

,

, etc.) get newlines before and after, with their content indented one level deeper. Inline elements (, , ) stay on the same line as their surrounding text to preserve word-break behaviour.
 and