Skip to main content

Free HTML Beautifier & Minifier

Pretty-print or minify HTML with proper nesting indentation. Preserves content inside <pre>, <script>, <style> blocks.

Works offline once loaded

Drop a file here, or click to browse

HTML, HTM · processed on your device

or press Ctrl+V to paste from your clipboard

Browse files
Beautified HTML
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.

  1. 1
    Tokenizer scans the markup
    A 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.
  2. 2
    Indentation depth is tracked per tag
    For 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.
  3. 3
    Minifier collapses whitespace safely
    In 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.
  4. 4
    Output is displayed and optionally saved
    The 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

Frequently Asked Questions