HTML minifier for smaller web pages
An HTML minifier makes a web page’s source smaller by removing unnecessary formatting and shortening markup. The aim is to send fewer bytes while preserving the page’s content and behavior. Knowing which parts are safe to change matters more than achieving the smallest possible file.
Loading the tool…
What is HTML minification?
Readable HTML often contains indentation, line breaks, comments and verbose attribute syntax. These help people maintain a website, but some are unnecessary in the version delivered to a browser. Minification parses that source and applies selected transformations to produce a more compact document.
For example, this HTML:
<p class="notice">Hello <strong>world</strong>.</p>
<input type="checkbox" disabled="disabled">
can be written more compactly as:
<p class=notice>Hello <strong>world</strong>.</p><input type=checkbox disabled>
Here, the attribute values allow unquoted syntax, and the boolean disabled attribute needs no repeated value. The space before <strong> stays: removing it would join two words. Minifying HTML is more careful work than deleting every space or line break.
The compact version is less pleasant to edit. Keep readable source as your working copy and treat minified HTML as a generated file you can recreate.
When is minifying HTML useful?
Minification is useful when templates or page generators produce substantial repeated formatting, especially across many pages or visits. Smaller responses can reduce transferred data and help loading when downloading the HTML is a bottleneck. A browser-based minifier is also convenient for comparing a snippet or checking whether a proposed optimization changes its markup.
The gain depends on the starting point. A small, already compact document may barely change. Large images, slow server responses or heavy JavaScript may dominate a page’s loading time, so saving a few HTML bytes will not solve those problems.
For SEO, assess the result through the visitor’s experience. Google’s Core Web Vitals guidance focuses on loading, responsiveness and visual stability. A smaller source file alone does not demonstrate an improvement in those measures; compare page performance before and after the change.
HTML minification versus gzip and Brotli
Minification changes the HTML source. HTTP compression such as gzip or Brotli encodes that source for transfer, and the browser decompresses it before processing the document. The two techniques can be used together; MDN’s guide to HTTP compression explains the server and browser negotiation.
The savings shown by this tool count uncompressed UTF-8 bytes. They are not a prediction of network savings. Repeated indentation may compress well already, while ordering attributes consistently can sometimes help compression without making the raw HTML shorter. Compare the actual transferred response size with the same compression and cache conditions before deciding an extra transformation is worthwhile.
Which minification options deserve care?
Whitespace and comments
Whitespace has meaning in text, between inline elements and in preformatted content. CSS can also preserve it through the white-space property. An HTML-only transformation cannot reliably infer every rule in external stylesheets. Start with conservative whitespace handling and inspect text spacing, code samples and layouts that depend on it.
Removing ordinary comments can reduce source size without changing the visible page. However, some comments are instructions for template processors, markers used by frameworks or conditional content for email clients. Preserve those deliberately; looking invisible in a browser does not make them disposable.
Attributes, optional tags and empty elements
| Transformation | Potential benefit | What to check |
|---|---|---|
| Remove optional attribute quotes | Shorter markup without changing valid attribute values | HTML permits unquoted values only under specific syntax rules; XML requires quotes. |
| Shorten boolean attributes | Replace forms such as disabled="disabled" with disabled | Boolean presence still means true; this rule does not apply to values such as aria-hidden="false". |
| Remove redundant attributes | Omit values that match HTML defaults | CSS selectors and scripts may depend on the attribute being explicitly present. |
| Omit optional tags | Reduce markup where HTML allows a tag to be inferred | Only certain tags and contexts qualify; HTML rules are not XML rules. |
| Remove empty elements | Delete markup believed to be unnecessary | Empty elements can be script mounting points, styled icons or layout containers. |
Omitting an optional tag is different from deleting an element: the HTML parser can reconstruct the implied structure. The HTML standard’s optional-tag rules define when that is valid. Removing an empty element removes the element itself, so leave that transformation off unless you know what each affected element does.
Embedded CSS, JavaScript and URLs
Minifying CSS and JavaScript inside HTML can save additional bytes, but it introduces transformations in two more languages. Check interactive behavior as well as appearance. If your build already optimizes these blocks, another pass may bring little benefit. Linked stylesheets and scripts are separate resources; this tool does not fetch or minify them.
URL shortening needs the document’s deployment context. A relative link that works at one path may resolve differently after a move or under a different base element. Keep existing URLs unless you can verify the final destinations.
Recommended use in a real website
Start conservatively, measure, then enable additional transformations one at a time. Gentle is a useful starting point here; Compact suits ordinary HTML you can test thoroughly. A preset cannot guarantee compatibility with every application.
For a recurring production workflow, integrate minification into the site’s build so the same settings apply on every release. Prefer processing final HTML after template rendering, and use a framework’s supported optimization path where available. Template delimiters and server-rendered framework markers need special care: preserving a few patterns does not make a general HTML parser understand the whole template language.
Before publishing, compare representative pages for readable text, layout, links, form behavior and script initialization, including framework hydration where applicable. Keep the original and the settings so you can reproduce or undo the result. For HTML email, test in the intended mail clients rather than relying on a browser preview alone.
Minification does not sanitize untrusted HTML or hide secrets. Scripts and dangerous attributes can remain, and visitors can still inspect the source. See HTML escaping versus sanitizing for that separate problem, or use the HTML encoder and decoder when you need to display markup as text.
How to use this tool
- Paste HTML into HTML source, open a local UTF-8 file, or load the example when the source is empty. Opening a file replaces the current source; an invalid file leaves it intact.
- Choose Gentle, Compact or Minimal changes. Click the underlined preset name at the right of the toolbar to open the selector, where each choice includes an explanation. Open a settings group for finer control. Reset options restores Gentle without clearing the source.
- With Auto minify enabled, changes update the output after a short pause. Turn it off to work manually with Minify. The Minify button turns into Cancel during processing; Cancel stops the current run and pauses automatic processing.
- Review the output and byte savings. A colored warning or error icon appears before the output copy button when something needs attention; hover, focus or tap it to read the message. Use the copy or download icon beside Minified HTML. Download creates
minified.htmlin UTF-8.
The source limit is 500,000 UTF-16 units, with a 1 MB limit for local files. Each run stops after 10 seconds; use a smaller input or simpler patterns if it times out. Inputs and results are kept only in page memory and cleared when you leave. Parsing failures clear the output; embedded CSS/JS failures show a warning because the library may retain the original embedded code. Clearing the source lets you load the example again.
Your tool data stays in your browser
This tool processes your data on your device. The text, files, or passwords you enter and the results it creates are not sent to our servers or any other server.
Page and asset requests still occur. Production pages also load Google Tag Manager, Cloudflare Web Analytics, and AdSense advertising; tool code does not send inputs or results to analytics or ads. See our privacy policy.
To inspect requests while using the tool, open your browser's developer tools and select Network. Try it with sample data.
Read How to Check Website Network Requests in Chrome, Firefox, Edge and Safari.
Minification reference
HTML Minifier Terser documents the engine used here, its transformations and preservation options. Use its option reference when choosing settings for a build pipeline.