HTML Formatter
Paste HTML and press Format to indent it by nesting depth, or Minify to strip whitespace and comments for production. The contents of pre, textarea, script and style blocks are left exactly as they were, so the page renders the same. The markup is only handled as text, so pasted scripts cannot run. Nothing is uploaded.
Updated
How to use the HTML Formatter
- 1Paste your HTML.
- 2Press Format to indent it, or Minify to compress it.
- 3Set your preferred indentation width.
- 4Copy the result or download it.
How it works
The formatter tokenises the markup into tags, text, comments and doctype declarations, then re-emits it with indentation tracking the nesting depth. Void elements such as img, br and input do not increase the depth, since they never close.
Some content must not be touched. Text inside pre and textarea is whitespace-significant — reindenting it changes what the page displays. Script and style blocks contain other languages entirely, where reindentation could break a template literal or a string. All four are passed through verbatim.
Minifying collapses whitespace between tags, removes comments and drops trailing spaces, while applying the same protections. It is a safe structural minify rather than an aggressive one: attribute quotes and optional closing tags are left alone, because removing them is where minifiers break pages.
The markup is only ever handled as text. It is never inserted into this page, so pasting hostile HTML here cannot execute anything.
Everything runs in this page. Nothing you paste is transmitted, logged or stored, which is what makes it safe to drop a production payload in here while you are debugging.
Tips and common mistakes
- Format for reading and editing; minify only the copy you ship.
- Pick an indentation width that matches your project's other files.
- Content inside pre, textarea, script and style is left exactly as it is, by design.
- Keep the formatted source under version control rather than the minified output.