HTML Minifier & Beautifier
Compress HTML for production or Beautify for readability (100% Client-side)
Preview is rendered in a sandboxed iframe for security. Some features may be limited.
HTML Minifier & Beautifier Documentation
What is this tool?
HTML minification removes characters that are irrelevant to browser rendering: inter-tag whitespace, HTML comments (<!-- -->), optional end tags (</li>, </td>, </p> per HTML5 spec), and boolean attribute values (disabled=“disabled” → disabled). Unlike CSS/JS minification, HTML minification must respect whitespace-significant elements (<pre>, <textarea>, <script>, <style>) and inline elements where inter-word spaces matter.
Key Features
- Whitespace and comment removal: collapses runs of whitespace between block-level tags; strips <!-- --> HTML comments (preserves <!--[if IE]--> conditional comments optionally); does not touch whitespace inside <pre>, <code>, <textarea> or script/style blocks.
- Optional end tag removal (HTML5): omits </li>, </dt>, </dd>, </p>, </th>, </tr>, </td>, </thead>, </tbody> where permitted by the HTML5 parsing algorithm without changing the DOM structure.
- Boolean attribute compaction: converts redundant value assignments (selected=“selected”, disabled=“disabled”, checked=“true”) to bare boolean form (selected, disabled, checked) per HTML5 spec.
- Configurable beautifier: reformats minified HTML with configurable indent (2/4 spaces or tab), properly nesting block and inline elements, expanding self-closing void elements (<br />→<br>), consistent attribute quoting.
- Attribute quote normalization: converts double-quoted attribute values to unquoted form where safe (class=“main” → class=main), reducing character count; reverted by beautifier for readability.
- Before/after file size delta: displays original byte count, minified/beautified byte count, and compression ratio to quantify minification benefit.
Common Use Cases
- Server-side rendering optimization: minify HTML output from PHP, Django, Rails, or Node.js template engines before sending to browser; reduces initial document size by 10-30% for markup-heavy pages.
- Static site generator post-processing: pipe HTML through minifier as final build step in Jekyll, Hugo, Eleventy, or Next.js static export; combine with Brotli compression for 85-95% total transfer reduction.
- Debugging minified HTML: beautify HTML from view-source on production sites or from API responses to inspect structure, check head metadata, and verify Open Graph / JSON-LD tags.
- Template audit: reformat auto-generated HTML from CMSs (WordPress, Drupal) or form builders to audit accessible markup, ARIA attributes, and heading hierarchy before QA.
Beautification Adjustments
The beautifier reconstructs proper indentation from flat or inconsistently indented HTML. It handles block vs. inline element distinction, preserves <pre> and <code> content verbatim, and normalizes self-closing tags and attribute quoting.
- Configurable indent: 2-space, 4-space, or tab characters
- Block elements begin on new lines; inline elements stay on same line
- Verbatim preservation of <pre>, <code>, <textarea> content
- Consistent double-quote normalization on all attributes
Minification Adjustments
HTML minification applies several passes, each controllable: whitespace collapsing, comment removal, optional end tag elision, boolean attribute compaction, and attribute quote removal.
- Inter-tag whitespace collapsed to single space or removed at block boundaries
- HTML comments stripped (configurable: keep IE conditional comments)
- Optional HTML5 end tags omitted where spec-safe
- Boolean attributes compacted to bare form
- Redundant attribute quotes removed where attribute value contains no spaces or special characters
Estimated File Size Impact
HTML minification typically achieves 10-30% reduction for pages with standard prose content. Template-heavy pages with many short tags and attributes achieve 20-40%. Minification benefit is proportionally smaller than CSS/JS because HTML text content cannot be further compressed without semantic change. Brotli on top of minified HTML achieves 85-95% total transfer reduction for typical page content.
Related Tools
CSS Minifier & Beautifier
Compress or beautify CSS code, remove whitespace and comments to optimize file size, or format code for readability
JavaScript Minifier & Beautifier
Compress or beautify JavaScript code, remove whitespace and comments to optimize file size, or format code for readability
HTML Encoder/Decoder
Convert special characters to HTML entities with named, decimal, and hexadecimal formats to prevent XSS attacks
XML Formatter
Format and validate XML data with syntax highlighting
JSON Formatter
Format and validate JSON data for improved readability and debugging
Text Diff Checker
Compare differences between two texts or files with side-by-side highlighted view