HTML Minifier
Compress HTML pages including inline CSS and JavaScript.
HTML Minifier – Minify HTML Online
The HTML minifier (also known as an HTML compressor) removes everything a browser does not need from your markup. It is powered by html-minifier-terser, a widely used minifier that also compresses inline <style> blocks and <script> tags. The savings are shown below the output.
What it removes and shortens
- Whitespace between tags and repeated spaces in text are collapsed.
- Comments are removed (conditional comments are respected).
- Boolean attributes are shortened:
checked="checked"becomeschecked. - Redundant attributes such as
type="text/javascript"on scripts andtype="text/css"on styles are dropped. - Doctype is shortened to
<!doctype html>. - Inline CSS and JavaScript are minified with the same engines as the CSS and JS minifiers.
Options
- Remove comments and Collapse whitespace – the two biggest savings, on by default.
- Minify inline CSS / JS – compress
<style>blocks,<script>blocks,styleattributes, and event handlers. - Remove optional tags – drops tags the HTML spec allows you to omit, such as
</li>,</p>,<head>, and<body>. Valid HTML, but some tools that parse HTML as XML will not like it. - Remove attribute quotes –
class="a"becomesclass=awhere it is safe.
When to minify HTML
Minify static pages, email templates (carefully — some email clients are picky), landing pages, and HTML fragments embedded in JavaScript. For server-rendered sites, minification usually happens in the build or at the CDN.
Whitespace caution
Collapsing whitespace can remove a visible space between inline elements in rare cases. Content inside <pre> and <textarea> is never changed.
Related tools
Make minified HTML readable with the HTML Beautifier, and minify external files with the CSS Minifier and JS Minifier.
Frequently Asked Questions
Does it minify inline JavaScript and CSS?
Yes. With the inline options enabled, <script> and <style> contents, style attributes, and inline event handlers are minified with Terser and clean-css.
Can minification break my page?
The default options are safe for standard HTML. Removing optional tags or attribute quotes is valid HTML but may confuse tools that expect XHTML. Whitespace between inline elements can occasionally change.
Should I minify HTML emails?
You can, but test the result in your email clients. Keep comments off only if you don't rely on conditional comments for Outlook.