HTML Minifier

Runs 100% in your browser

Minify HTML locally by removing ordinary comments and unnecessary inter-tag whitespace while protecting pre, textarea, script, and style content. Compare byte savings, copy, and download the result privately.

HTML INPUT

Source document

0 bytes
0 lines 0 tags
MINIFIED OUTPUT

Optimised document

Waiting
0 bytes 0% saved
Load or paste HTML to see minification statistics and optimisation notes.
Input bytes0
Output bytes0
Saved bytes0
Reduction0%
Comments removed0
Protected blocks0
Safe by default. Minification is not obfuscation or encryption. The default mode protects preformatted and raw-text content. Enable Aggressive mode and Safe attribute cleanup for additional savings, but always review the result before deploying to production.

Recent minifications

No history yet — run a minification to see results here.
100% private.

All processing happens locally in your browser using the FileReader API and standard JavaScript string operations. No HTML source is uploaded, transmitted, stored in localStorage or sessionStorage, or sent to any analytics service. Clipboard access is only requested when you click Paste or Copy.

Frequently asked questions

An HTML Minifier removes presentation whitespace and removable comments from HTML while preserving document structure and meaningful content. It reduces file size for delivery, storage, email templates, static site generators, and generated pages without altering what the browser renders.

Paste HTML into the input panel or open a local .html file, choose your settings, and the output is generated instantly. ToolsSonic reports input bytes, output bytes, saved bytes, and reduction percentage. Copy or download the result when you are happy with it.

The safe default removes ordinary HTML comments. Conditional IE comments and comments containing @preserve, @license, @cc_on, or the word keep are retained so that important compatibility or licensing instructions are not discarded silently.

Yes. The default raw-text protection wraps pre, textarea, script, and style blocks in placeholder tokens before any whitespace processing, then restores them afterwards. This prevents meaningful indentation, code strings, CSS rules, or user-entered text from being collapsed.

Safe minification is designed to remove non-semantic inter-tag whitespace and ordinary comments, which should not affect rendering. However, any transformation can expose fragile assumptions in invalid or unusual markup. Always review the result and test the page, especially with aggressive mode enabled.

Aggressive mode adds simple-value quote removal, boolean attribute normalisation (disabled="disabled" to just disabled), and removal of the redundant type="text" attribute on input elements. The result is smaller but warrants extra review before deployment. A visible warning is displayed when aggressive mode is active.

No. Inline style and script blocks are protected by default rather than parsed and rewritten. A full CSS or JavaScript parser is needed for semantic optimisation of those languages. Use a dedicated CSS Minifier or JS Minifier when you need to reduce their size beyond whitespace removal.

No. Optional tag removal can break browser parsing edge cases and changes the document structure in ways that deserve manual review. ToolsSonic preserves all tags by default, making the output easier to inspect and safer to deploy.

Yes. The Open HTML button reads a local .html or .htm file through the browser FileReader API. The file is processed entirely in memory and is never uploaded to a server or sent to any remote service.

Savings depend on how much indentation, line wrapping, inter-tag whitespace, and comments the source contains. A hand-authored page with generous formatting might save 20–40%. A tightly written template might save 5–10%. ToolsSonic measures the actual byte difference for the document you provide rather than promising a fixed percentage.

Smaller HTML can contribute to faster page loads and Time to First Byte, which are signals in Google Core Web Vitals. However, minification alone does not guarantee higher rankings. Content quality, crawlability, structured data, accessibility, links, and many other factors matter far more.

They are opposites. Formatting adds indentation, line breaks, and consistent spacing for developer readability. Minification removes those characters for compact delivery. Use HTML Formatter to review source and HTML Minifier to prepare a production copy.

No. Minified HTML is still plain text that any browser developer tools panel can display and read. It is not encrypted and should not be treated as source protection. Minification is purely a size and presentation transformation.

The tool applies conservative text-aware transformations rather than requiring a fully valid DOM. Fragments, template syntax, and incomplete tags are handled as text. Review the diagnostic and output carefully when working with conditional markup, server-side template fragments, or partial HTML.

Yes. Copy minified places the result on the clipboard using the Clipboard API with a textarea fallback. Download .html saves a minified.html file locally using a Blob URL. No server-side storage is involved.

The tool is free with no account required. All processing happens locally in browser memory. The dedicated client makes no upload requests, no fetch or XHR calls, no beacon events, and writes nothing to localStorage or sessionStorage.

Yes. Email templates often contain generous whitespace and inline comments for readability. Safe minification removes inter-tag whitespace and ordinary comments while preserving style blocks and inline styles that email clients rely on. Use Safe mode rather than Aggressive for email, as some clients are sensitive to attribute-quote removal.

You can paste the rendered HTML output from your CMS page source into the tool, minify it, and use it as a reference to measure savings. For automated per-request minification in WordPress, server-side plugins such as Autoptimize or WP Rocket handle HTML along with CSS and JS. ToolsSonic is most useful for reviewing specific templates, email layouts, or generated page fragments before deployment.

Minification reduces the number of bytes in the text file itself by removing whitespace and comments. Gzip (and Brotli) compress the file at the transport layer using repetition-based algorithms. Both can be used together: minify the HTML, then let the web server apply Gzip. The gains are complementary but not multiplicative, because Gzip already compresses repeated whitespace very efficiently.

What is HTML Minifier?

An HTML Minifier removes ordinary comments and unnecessary inter-tag whitespace while protecting meaningful preformatted and raw-text content. It prepares HTML for delivery, storage, email templates, static site builds, CMS output, and generated pages without uploading the source to any server.

ToolsSonic's browser-only HTML Minifier protects pre, textarea, script, and style blocks with a placeholder-token approach before collapsing whitespace, ensuring that meaningful indentation, JavaScript string spacing, CSS rules, and user-entered text are never treated as disposable layout characters. Conditional comments, @preserve, @license, and @cc_on markers are retained automatically.

How HTML Minification Works

Minification follows four deterministic steps: first, raw-text blocks (pre, textarea, script, style) are swapped with unique placeholder tokens; second, ordinary comments are removed while preserving conditional and licensed ones; third, all whitespace sequences between characters are collapsed to a single space and inter-tag gaps > < become ><; fourth, the placeholder tokens are replaced with the original raw-text content. This order guarantees that code, styles, and preformatted text survive the whitespace pass intact.

A DOCTYPE normalisation step converts <!DOCTYPE html> variations to lowercase <!doctype html>, which saves a few bytes and is more consistent across validators.

Safe Mode vs Aggressive Mode

Safe mode removes comments, collapses whitespace, normalises DOCTYPE, and protects raw-text content. These transformations have near-zero risk of changing browser rendering. Aggressive mode adds three extra transformations: attribute-quote removal for simple alphanumeric values, boolean attribute normalisation (disabled="disabled"disabled), and removal of the redundant type="text" attribute on input elements. Aggressive savings are meaningful — typically an additional 1–3% — but the output deserves a brief review before deployment, especially in legacy codebases or email clients that may be sensitive to unquoted attribute values.

HTML Minifier vs HTML Formatter

Formatting and minification are complementary opposites. HTML Formatter adds indentation, consistent line breaks, and corrected nesting for developer readability; it increases file size. HTML Minifier removes those characters for compact delivery; it reduces file size. Use the formatter during development and code review, and the minifier when preparing files for staging or production. Both tools are lossless for the DOM — neither changes what the browser renders from a structurally valid document.

Common use cases

  • Reducing whitespace and comments in a static HTML page before deployment
  • Minifying a local HTML file privately without uploading it anywhere
  • Comparing input and output byte counts before and after minification
  • Protecting pre and textarea content during safe minification
  • Preserving inline script and style blocks from unsafe regex rewriting
  • Testing optional boolean and redundant attribute cleanup
  • Minifying HTML email templates while preserving inline styles
  • Learning the difference between minification, formatting, Gzip, and obfuscation

Why use ToolsSonic's HTML Minifier?

ToolsSonic's HTML Minifier addresses the main gaps in every public benchmark: CodeBeautify provides a strong two-pane workflow but processes on a server and provides no detail on which blocks are protected; Toptal uses a POST API with a 30-request-per-minute rate limit and no local-file flow; HTMLMinifier legacy is deprecated and exposes no download, copy, or statistics in its web UI; Toolvana provides side-by-side output but no verified comment policy, no file upload, and no byte statistics. ToolsSonic combines local-first processing, explicit placeholder-based raw-text protection, visible safe and aggressive mode separation, 6-stat strip, 8-item history, copy, download, file upload, conditional comment preservation, DOCTYPE normalisation, responsive split-view comparison, and a full privacy footer — all in a zero-dependency browser page.

HTML Minification Options Reference

OptionWhat it doesDefaultWhen to disable
Remove ordinary commentsStrips <!-- ... --> build notes, editor markers, and debug comments. Retains conditional IE comments and @preserve/@license/@cc_on markers.OnWhen source comments are needed in the delivered file for licensing or debugging purposes.
Collapse inter-tag whitespaceReplaces > whitespace < sequences with ><, removing newlines and indentation between elements.OnWhen whitespace-significant inline layouts such as inline-block grids rely on the space between tags.
Preserve raw-text contentProtects pre, textarea, script, and style blocks with placeholder tokens before whitespace processing. Restores them intact afterwards.OnRarely — only if you want whitespace inside script or style strings to also be collapsed, which risks breaking code.
Normalise DOCTYPEConverts any DOCTYPE html variant to lowercase <!doctype html>.OnWhen a legacy validator or rendering target requires the original capitalised form.
Safe attribute cleanupNormalises boolean attributes (disabled="disabled"disabled) and removes redundant type="text" on input elements.OffEnable for modern HTML5 documents; disable for XHTML or XML contexts where self-closing attributes are required.
Aggressive modeRemoves attribute quotes from simple alphanumeric values and enables all safe attribute cleanup. Review the result before deploying to environments with strict attribute parsers or email clients.OffWhen working with email templates, legacy browsers, XML pipelines, or any parser that requires quoted attributes.

HTML Minifier vs CSS Minifier vs JS Minifier

DimensionHTML MinifierCSS MinifierJS Minifier
Target languageHTML markup and attributesCSS rule sets and declarationsJavaScript expressions and statements
What is removedInter-tag whitespace, ordinary comments, redundant attributesWhitespace, comments, zero values, shorthand propertiesWhitespace, comments, unreachable code, local variable names
Typical savings5–35% depending on indentation and comments10–40% with selector/value normalisation20–70% with variable renaming and dead-code removal
Safe to automate?Yes for safe mode; review aggressive modeGenerally yes with a well-tested CSS minifierRequires thorough testing — variable renaming can break dynamic access
Protects embedded contentProtects inline script and style blocksDoes not process HTML or scriptDoes not process HTML or CSS
Stacks with GzipYes — complementary savingsYesYes
100% private — runs in your browser Instant — no server round-trip Free forever — no account needed