Skip to content
AllToolsDesk

Popular

  • JSON Formatter & ValidatorFormat, minify and validate JSON with error locations.
  • CSS FormatterBeautify CSS, SCSS and Less with Prettier.
  • CSS MinifierCompress CSS and see the bytes saved.
  • JavaScript FormatterBeautify JavaScript and TypeScript.
  • JavaScript MinifierMinify JavaScript with Terser.
  • HTML FormatterIndent HTML, including inline CSS and JS.
  • JPG to PDFTurn images into a PDF, one per page.
  • Merge PDFCombine several PDFs into one file.
38 free toolsSee all tools

HTML Minifier

Minify HTML: strip comments and extra whitespace, and compress inline <style> and <script> blocks. Pre and textarea content is kept. Runs in your browser.

Runs in your browser. Nothing is uploaded.

Ready.

About the HTML Minifier

Minified HTML loads faster because there is less to download before the browser can start building the page. The savings matter most for large static pages, HTML emails with size limits, and markup embedded in scripts or databases.

This minifier removes comments and whitespace that browsers ignore, and compresses inline CSS and JavaScript using the same engines as the dedicated minifiers on this site. It is careful where whitespace matters: text between inline elements keeps a single space, and the content of pre and textarea elements is left exactly as written, so the page looks the same afterwards.

How to use the HTML Minifier

  1. 1

    Paste your markup, open an .html file, or load the sample. Pasting, opening a file or loading the sample runs it automatically.

  2. 2

    Choose whether to remove comments and compress inline CSS and JavaScript.

  3. 3

    Press Minify. The status bar shows how many bytes were saved.

  4. 4

    Copy the result or download it as .min.html.

Examples

1Drop comments and whitespace between blocks
Before
<ul>
  <!-- links -->
  <li><a href="/a">A</a></li>
  <li><a href="/b">B</a></li>
</ul>
After
<ul><li><a href="/a">A</a></li><li><a href="/b">B</a></li></ul>
2Keep the space between inline elements
Before
<p>
  Read the <a href="/docs">docs</a>   or   <em>ask</em>.
</p>
After
<p>Read the <a href="/docs">docs</a> or <em>ask</em>.</p>
3Compress an inline style block
Before
<style>
  .btn { color: #ffffff; margin: 0px; }
</style>
After
<style>.btn{color:#fff;margin:0}</style>

Good to know

  • Whitespace is removed only next to block-level tags such as <div>, <p> and <li>. Between inline elements it is collapsed to one space, because removing it would change the rendered text.
  • Content inside <pre> and <textarea> is kept exactly as written.
  • Conditional comments (<!--[if IE]>) and comments starting with <!--! are kept.
  • Inline scripts with a syntax error, and JSON scripts that do not parse, are left as is and listed as warnings.
  • Template syntax (Blade, Handlebars, JSX) is not understood and may be altered. Minify the rendered HTML instead.

Frequently asked questions

Is it safe to minify inline JavaScript?

Yes for standard scripts. Top-level names are not renamed, so code in other scripts that uses them keeps working.

Does CSS white-space: pre still work after minifying?

Not for elements other than <pre> and <textarea>. If an element relies on white-space: pre or pre-wrap, its spacing will be collapsed.

Is my code uploaded to a server?

No. Processing happens entirely in your browser, in a background thread. Your input is never sent to our servers or stored anywhere.

More tools that pair well with this one.

Browse all tools