A fast and efficient command-line tool to minify your HTML, Razor views, and Web Forms views. Reduce file sizes, improve load times, and deliver a better user experience by removing unnecessary whitespace and comments from your HTML files.
- π Fast Processing - Minifies files and entire directory trees quickly with parallel processing
- β‘ Parallel Processing - Utilizes all CPU cores for maximum performance (4-8x faster on multi-core systems)
- π Beautiful Reporting - Comprehensive statistics with progress tracking and professional visual presentation
- π Flexible Input - Process individual files, specific folders, or entire directory structures
- βοΈ Configurable - Control line length and selectively disable minification features
- π§ Framework Support - Special handling for Knockout.js, Angular, and other comment-dependent frameworks
- π― Targeted Minification - Choose what to minify: HTML comments, JavaScript comments, or Knockout comments
- π‘οΈ Safe Minification - Preserves content inside
<pre>,<textarea>, and<code>tags, and normalises attribute whitespace - π CI/CD Ready - Easy integration with MSBuild and build pipelines
- Download the latest release from the releases page
- Extract the
HtmlMinifier.exeto your desired location - Add the tool to your PATH or reference it directly
Transform verbose HTML into compact, optimized code:
<h2>
Admin Menu</h2>
<ul>
<li>@Html.ActionLink("Edit blog entries", "List", "Admin")</li>
<li>@Html.ActionLink("View Comments", "CommentList", "Admin")</li>
<li>@Html.ActionLink("Clear Cache", "ClearCache", "Admin")</li>
</ul><h2> Admin Menu</h2><ul><li>@Html.ActionLink("Edit blog entries", "List", "Admin")</li><li>@Html.ActionLink("View Comments", "CommentList", "Admin")</li><li>@Html.ActionLink("Clear Cache", "ClearCache", "Admin")</li></ul>View all available options:
HtmlMinifier.exe --helpCheck the version:
HtmlMinifier.exe --versionMinify all HTML files in a folder (including subfolders):
HtmlMinifier.exe "C:\Folder"Restrict the maximum number of characters per line:
HtmlMinifier.exe "C:\Folder" "60000"For frameworks that rely on HTML comments (Angular, Knockout, etc.), preserve them:
HtmlMinifier.exe "C:\Folder" ignorehtmlcommentsKeep JavaScript comments in your code:
HtmlMinifier.exe "C:\Folder" ignorejscommentsSpecifically preserve Knockout.js comments:
HtmlMinifier.exe "C:\Folder" ignoreknockoutcommentsHtmlMinifier.exe "C:\Folder\fld1" "C:\Folder\fld2"HtmlMinifier.exe "C:\Folder\file1.html" "C:\Folder\file2.html"Integrate HTML Minifier into your build process for automatic minification during deployment. Check out this detailed guide on using HTML Minifier with MSBuild.
The following content is never altered by minification:
<pre>,<textarea>,<code>tags β internal whitespace is kept exactly as-is- IE conditional comments β
<!--[if IE]>,<!--[if !IE]><!-->, and<!--<![endif]-->patterns are all preserved #includevirtual comments β ASP.NET server-side includes are left intact- Knockout comments β
<!-- ko -->/<!-- /ko -->are preserved whenignoreknockoutcommentsis set - Razor declarations β
@model,@using,@inheritsare kept and correctly re-arranged - Attribute values β content inside quotes is preserved; leading/trailing whitespace is normalised
Contributions are welcome! Please feel free to submit a Pull Request.
- .NET Framework (Windows)
- Supports HTML, Razor (.cshtml), and Web Forms (.aspx) files
Copyright (C) Dean Hume 2013 - 2025
Released under the MIT License
Made with β€οΈ by Dean Hume