Free HTML Minifier

Paste HTML or upload .html files to shrink them: whitespace, comments and inline CSS/JavaScript formatting are removed, while every tag and attribute is kept and whitespace is only removed where browsers ignore it, so the page works and looks the same unless your stylesheet changes how block tags are laid out (see the tips). The result updates as you type and is created in your browser; nothing is uploaded.

Upload HTML Files

Minification Options
Original Size
1.45 KB
1,488 bytes
Minified Size
1.05 KB
1,071 bytes
Saved
0.41 KB
417 bytes
Reduction
28.0%
of the original size
61 lines โ€ข 1,488 characters
5 lines โ€ข 1,071 characters

โœจ Minification Features:

โœ… Remove whitespace
โœ… Remove comments
โœ… Collapse boolean attributes
โœ… Minify inline CSS
โœ… Minify inline JS and JSON
โœ… Size comparison
โœ… Batch files to ZIP
โœ… Minifies as you type
โœ… Keeps pre/textarea content

๐Ÿ’ก Tips:

  • โ€ข Savings depend on how much indentation, blank lines and comments the page has
  • โ€ข Text inside pre and textarea tags is never changed
  • โ€ข Script and style tags keep all their attributes (src, defer, async, media, type)
  • โ€ข If your CSS sets white-space: pre on ordinary elements, turn off Collapse whitespace
  • โ€ข If your CSS makes li or div elements inline-block, turn off Collapse whitespace, or the gap between them disappears (inline style attributes are detected automatically)
  • โ€ข The same goes for CSS that hides, floats or absolutely positions a block element between two words: the space around it can disappear (the hidden attribute and inline styles are detected automatically)
  • โ€ข Turn on gzip or Brotli compression on your server as well; it works on top of minification
  • โ€ข All processing happens in your browser - completely private

How to minify HTML online, free and private

HTML minification removes the characters a browser does not need, so the file is smaller to download. Here, paste your markup into HTML Input, or click Open a File, and Minified Output updates as you type. The panels show Original Size, Minified Size, Saved and Reduction. Then click Copy Minified or Download .html.

It runs in your browser; nothing is uploaded (you can check the Network tab in DevTools).

The minifier removes whitespace where browsers ignore it, ordinary comments, and the formatting inside style and script blocks. Every tag and attribute stays. It is not a full JavaScript compressor: it does not rename variables or build source maps, so for external files use the CSS minifier and the JavaScript minifier. To read a minified page again, run it through the HTML beautifier.

Table of Use: what each option does

The six minification options, whether each is on by default, and an example of what it changes
JobOption (default)Example change
Remove indentation and line breaksCollapse whitespace (on)<h1>Hello</h1> and the next <p> on separate lines join into one line. A space between <b> and <i> is kept.
Strip developer commentsRemove comments (on)<!-- Styles --> is deleted; <!--[if mso]> is kept
Shrink style blocksMinify inline CSS (on)body { margin: 0; } becomes body{margin:0}
Shrink script blocksMinify inline JavaScript (on)Comments and indentation go, line breaks stay, and JSON-LD is compacted
Shorten boolean attributesCollapse boolean attributes (on)disabled="disabled" becomes disabled
Drop quotes around simple valuesRemove attribute quotes (off)class="nav" becomes class=nav; a value with a space keeps its quotes
Several pages in one goMinify Several Files (ZIP)A before-and-after size for each file, then minified-html.zip

Tags such as <script src="/js/app.js" defer> and <style media="print"> keep every attribute. Content inside pre and textarea tags is never changed. Check the minified page in the HTML previewer, and shrink JSON-LD or API samples with the JSON minifier.

Features

  • Minifies as you type. There is no Minify button. The output follows the input, and the size panels show bytes and percent saved.
  • Six options. Collapse whitespace, Remove comments, Minify inline CSS, Minify inline JavaScript, Collapse boolean attributes and Remove attribute quotes, each a checkbox with a hint.
  • Attributes are safe. Every attribute is kept, including src, defer, async, media and type on script and style tags. Style attributes are left exactly as written.
  • Careful with code. The JavaScript pass keeps line breaks, copies strings, template literals and regular expressions unchanged, and only compiles code to check it still parses; it never runs it. If a script cannot be processed with confidence, the original stays.
  • Open a File and batches. Load one .html or .htm file, or several at once and download a ZIP with the original names.
  • Copy Minified, Download .html, Clear. The download is named minified.html.
  • Private and free. No account, and nothing is uploaded or saved.

Shrink the images on the page too, with the image compressor, and turn on gzip or Brotli on your server for a smaller transfer on top of minification. The HTTP header viewer shows whether a page is served compressed.

How to use the HTML minifier

  1. Paste your HTML into HTML Input, or click Open a File to load a .html or .htm file. The box starts with a sample page; click Clear to empty it.
  2. Under Minification Options, tick or untick the six checkboxes. The defaults suit most pages.
  3. Read the Original Size, Minified Size, Saved and Reduction panels.
  4. Check Minified Output. The counts above the box show lines and characters.
  5. Click Copy Minified, or Download .html to save minified.html.
  6. For many files, click Minify Several Files (ZIP), pick the files, review Batch Results and click Download All (ZIP).
  7. Test the result before publishing. If your CSS makes li or div elements inline-block, or sets white-space: pre on ordinary elements, untick Collapse whitespace and minify again.

Who can use it

  • Web developers shipping static pages who want a smaller file without setting up a build tool.
  • Email template builders, whose conditional comments for Outlook are kept. Build the table-based HTML with the email template builder, then minify it here.
  • SEO and performance specialists checking how much weight whitespace and comments add to a page.
  • Writers and theme authors trimming HTML from the Markdown to HTML converter, or snippets pasted into a CMS.
  • Students comparing a page before and after, with the text diff tool.

FAQs

How do I minify HTML online?

Paste your HTML into HTML Input, or click Open a File to load a .html file. Minified Output updates as you type, and the panels above show Original Size, Minified Size, Saved and Reduction. Adjust the Minification Options if needed, then click Copy Minified or Download .html. Nothing is uploaded, because the work happens in your browser.

Will minifying HTML break my page?

It is built not to. Every tag and attribute is kept, including src, defer, async, media and type on script and style tags, and whitespace is removed only where browsers ignore it. One space stays between inline elements so words do not run together. The risk is CSS the tool cannot see, such as rules that make li or div inline-block or set white-space: pre. For those pages, untick Collapse whitespace.

How much smaller will my HTML get?

It depends on the page. Hand-written HTML with deep indentation, blank lines and comments shrinks the most, while HTML that a framework has already minified barely changes. The tool shows the exact original and minified sizes in bytes for your input, so you can measure instead of guessing. Gzip or Brotli on your server then compresses the result further.

Does the minifier remove HTML comments?

Yes, when Remove comments is ticked, which it is by default. Ordinary comments are deleted. Conditional comments such as the Outlook block that starts with an if mso test are kept, because many email templates rely on them, and so are comments that begin with an exclamation mark. Untick Remove comments to keep every comment in the output.

Why does the minified JavaScript still contain line breaks?

JavaScript can insert missing semicolons at line breaks, so joining lines could break code written without semicolons. The minifier removes comments and indentation but keeps the line breaks. Strings, template literals and regular expressions are copied exactly, and it does not rename variables. For aggressive compression of external scripts, use the JavaScript minifier or a build tool.

Does it minify JSON-LD and other script types?

JSON script blocks, including JSON-LD, importmap and speculation rules, are compacted without re-reading numbers, so large numbers keep every digit. Classic and module scripts get comment and indentation removal. Script types that are not JavaScript or JSON, such as text/template, are left untouched. If a script cannot be processed with confidence, the original is kept.

Can I minify several HTML files at once?

Yes. Click Minify Several Files (ZIP) and select your .html or .htm files. A list shows each fileโ€™s size before and after, and it recalculates when you change an option. Click Download All (ZIP) to get minified-html.zip with the original file names. The ZIP is built in your browser too, and nothing is sent anywhere.

Is my HTML uploaded to a server?

No. Files are read and minified in your browser, and the ZIP for several files is built there as well, so nothing is uploaded (you can check the Network tab in DevTools). The tool does not save your input: reload the page and the sample returns. It is free, with no account and nothing to install.