HTML Formatter
Pretty-print or minify HTML — with pre, script and style left intact.
About this formatter
Format mode re-indents tag soup at two spaces per level, keeps inline runs (<a>, <b>, <span>…) together so sentences don't shatter, and preserves <pre>, <script> and <style> contents byte-for-byte. Minify mode strips comments and inter-tag whitespace. Neither rewrites your tags.
The three regions a formatter must not touch
HTML formatting has landmines that generic pretty-printers step on reliably. Inside <pre>, whitespace IS content — re-indent it and the code sample it displayed is corrupted. Inside <script> and <style>, the content isn't markup at all — it's JavaScript and CSS with their own grammars, where an HTML formatter's "help" means syntax errors. This tool treats all three as sealed boxes, copied byte-for-byte — which is precisely the behaviour that lets you format a full page without auditing the result. The other craft choice: inline elements stay on their line. Naive formatters put every tag on its own row, exploding "some <b>bold</b> text" into five lines and — worse — sometimes introducing visible whitespace where none existed (space IS significant around inline elements). And deliberately absent: tag "fixing". A formatter that closes your tags for you is editing your document; browsers already have famously robust repair, and guessing differently from them helps no one. Preview renders the result live; XML, JSON and SQL formatters complete the set.
Frequently asked questions
Will it break my <pre> blocks or inline scripts?
No — <pre>, <script>, <style> and <textarea> contents are preserved byte-for-byte, sealed from formatting. That's the difference between an HTML-aware formatter and a generic one.
Why aren't all tags on their own lines?
Inline elements (<b>, <a>, <span>…) stay in their text runs — splitting them shatters sentences and can introduce visible spaces, since whitespace around inline elements renders. Block structure gets the indentation.
Does it fix unclosed tags?
Deliberately not — that's editing, not formatting, and the browser's own repair (famously robust) may disagree with any guess. What you wrote is what gets indented.
What does minify mode remove?
Comments and whitespace between tags — the safe reductions. Text content and the sealed regions are untouched; typical pages shrink 10–25% before gzip.