Free HTML Beautifier & Minifier
Pretty-print or minify HTML with proper nesting indentation. Preserves content inside <pre>, <script>, <style> blocks.
Drop a file here, or click to browse
HTML, HTM · processed on your device
or press Ctrl+V to paste from your clipboard
Output will appear here…Common uses
- Debug Server-Rendered HTMLView raw HTML output from your server (PHP, Rails, Django, Node) in a readable indented format.
- Format Email HTML TemplatesEmail HTML is verbose (tables, inline styles). Format to make it editable and maintainable.
- Format Static HTML PagesManually-edited static HTML files benefit from consistent formatting for collaborative editing.
- Clean Up CMS-Exported HTMLWordPress, Wix, Squarespace export HTML with lots of artifacts. Format to make it editable.
- Minify HTML for ProductionReduce HTML file size for faster page loads by stripping whitespace and unnecessary characters.
How It Works
This tool formats or compresses HTML using a hand-written tag-aware tokenizer built directly into the page — no third-party formatting library, no server round-trip. Every character of your markup is processed locally in the browser the moment you type or paste it.
- 1Tokenizer scans the markupA custom character-by-character scanner walks the HTML string, identifying comments, DOCTYPE declarations, opening tags, closing tags, self-closing void elements (br, img, input, etc.), and raw text nodes. A dedicated helper tracks quoted attribute values so characters like > inside an attribute (e.g. value="a>b") never cause a tag to split early.
- 2Indentation depth is tracked per tagFor beautify mode, the tokenizer maintains a depth counter. Block-level opening tags increase depth; closing tags decrease it before they are written. Inline elements (span, a, strong, em, etc.) are kept on the same line as their content rather than pushed to their own indented line. Tags like pre, script, style, and textarea have their inner content emitted verbatim to avoid corrupting whitespace-sensitive or executable code.
- 3Minifier collapses whitespace safelyIn minify mode, the content of pre, script, style, and textarea blocks is swapped out for numbered sentinels before any whitespace collapsing happens. HTML comments are stripped, and runs of whitespace between tags are removed — except between adjacent inline elements, where a single space is preserved so words do not fuse together. Sentinel placeholders are then restored to their original content.
- 4Output is displayed and optionally savedThe formatted or minified result appears live in the output panel alongside a size-change percentage. You can copy it to the clipboard or download it as a .html file, all without leaving the browser.
Related Tools
CSS Beautifier
Pretty-print minified CSS with consistent indentation, or minify it. Optional alphabetical property sorting for predictable diffs.
CSS Minifier & Beautifier
Minify CSS to reduce file size or beautify minified CSS for readability. Instant, in your browser.
XML Formatter & Validator
Pretty-print and validate XML using your browser's native DOM parser. Includes minified output for production use.