AnyTool
Your files never leave your device. All processing happens locally in your browser.

How do I minify HTML to reduce its file size?

Paste HTML into AnyTool and it minifies in real time — collapsing whitespace, removing comments, and minifying inline CSS and JavaScript — using an AST-based engine. It shows original, minified, and gzip sizes live and runs entirely in your browser with no upload.

  • Collapse whitespace, remove comments, minify inline CSS/JS
  • Safe/Balanced/Aggressive presets plus granular options
  • Live original vs minified vs gzip size savings
  • Copy, download, and file drag-and-drop
  • 100% in-browser — no upload, works offline

What is

HTML Minification

HTML minification removes unnecessary characters — whitespace, comments, optional tags and attributes — and compresses inline CSS and JavaScript, reducing file size and load time without changing how the page renders.

Developer Tools

Related terms

MinificationGzipInline CSSInline JSPage Speed

Frequently Asked Questions

Yes — it parses the HTML, so whitespace-sensitive tags like pre and textarea are preserved.

Because it uses a real parser rather than regex, it avoids breaking edge cases: content inside pre, code, textarea, script, and style is left intact, and a conservative preset is available for extra safety.

Yes — inline style and script blocks are minified along with the HTML.

The AST-based engine minifies <style> and <script> blocks (and event/style attributes) in addition to collapsing HTML whitespace and removing comments, with toggles so you control exactly what gets optimized.

It is free and your HTML is never uploaded — minification runs in your browser.

Unlike server-side minifiers that POST your markup to an API, this tool runs entirely client-side with the engine bundled locally, so your HTML stays private and it works offline after first load.

Detailed Explanation

Methodology

How the HTML Minifier Works

AnyTool minifies HTML with an AST-based engine (html-minifier-terser) that delegates inline JavaScript to terser/Oxc and inline CSS to clean-css. It collapses whitespace, removes comments and optional/redundant attributes, and optionally minifies inline styles and scripts, while safely preserving whitespace-sensitive tags such as pre, code, textarea, script, and style. Safe/Balanced/Aggressive presets and granular toggles control the output, and original, minified, and gzip sizes (via CompressionStream) update live.

  • AST-based engine, not regex
  • Minifies inline CSS and JavaScript
  • Preserves pre/code/textarea/script/style content
  • Safe/Balanced/Aggressive presets plus granular options
  • Live original, minified, and gzip size stats
Privacy & Security

Privacy and Offline Use

The minifier engine is bundled at build time and runs client-side (in a Web Worker for large inputs), so HTML is never uploaded — unlike server-side minifiers that POST your markup to an API. The tool works offline after first load with no runtime CDN.

HTML Minifier: AnyTool vs typical tools
CapabilityAnyToolTypical tools
EngineAST-basedOften regex
Inline CSS/JS minifyYesSometimes
Gzip size statsYesRare
Processing locationIn-browserSometimes server-side
Works offlineYesNo

Capabilities reflect the live AnyTool tool; competitor behavior varies by service.