Home › Developer Tools › HTML Minifier

HTML Minifier

Paste your HTML to strip comments and needless whitespace while keeping <pre>, <textarea>, scripts and conditional comments safe. See the size before and after and copy or download the result.

Last updated:

Options
Original–
Minified–
Saved–

Advertisement

How to use the HTML Minifier

  1. Paste your HTML into the input box, or press Upload .html (you can also drop a file onto the box).
  2. Pick your options. The defaults are safe for almost every page; turn on “Remove optional attribute quotes” for a few extra bytes.
  3. Press Minify HTML. The output also updates live while you type.
  4. Check the savings in the Original, Minified and Saved cards.
  5. Copy or Download the minified HTML and use it in production. Keep your readable original for editing.

What the HTML minifier changes (and what it never touches)

InputOutputWhy it is safe
<!-- nav -->(removed)Comments are never displayed.
<div>⏎␣␣<p>Hi</p>⏎</div><div><p>Hi</p></div>Whitespace between block elements does not render.
<b>a</b>␣␣⏎<i>b</i><b>a</b>␣<i>b</i>One space is kept between inline elements so words stay apart.
class="a␣␣␣b"class="a b"Class lists are space-separated tokens.
checked="checked"checkedFor boolean attributes only presence matters.
<script type="text/javascript"><script>JavaScript is the default script type in HTML5.
<br /><br>Void elements need no closing slash in HTML5 (SVG keeps its />).
<pre>, <textarea>(unchanged)Whitespace is meaningful inside them.

Worked example: how the savings are calculated

The saving is (original bytes − minified bytes) ÷ original bytes × 100, measured in UTF-8 bytes, which is what your server actually sends. If a template is 18,400 bytes and the minified version is 14,720 bytes, you save 3,680 bytes, which is 3,680 ÷ 18,400 = 20%.

Minification and compression work together. Gzip or Brotli shrink repeated text extremely well, so a 20% saving before compression often becomes a 5–10% saving after it. That is still worthwhile on pages served millions of times, and minified HTML is also parsed slightly faster.

Tips for minifying HTML safely

  • Minify as part of your build or deploy step and keep the readable source in version control.
  • If you rely on white-space: pre in CSS for an element other than <pre>, keep that content in a <pre> or turn off whitespace collapsing.
  • Inline scripts are minified lightly and conservatively. For bundles of JavaScript use a dedicated tool such as a JS minifier in your build.
  • Template placeholders like {{ name }} are left intact because they are ordinary text.

Frequently asked questions

What does an HTML minifier do?

It removes characters the browser does not need, such as comments, indentation and line breaks between tags, so the file is smaller and downloads faster. The page looks and behaves the same.

Is it safe to minify HTML?

Yes, when whitespace is handled carefully. This tool keeps a single space between inline elements and words, leaves <pre> and <textarea> content untouched and never rewrites the contents of strings in scripts. Always test the minified page once before deploying.

How much smaller will my HTML get?

Typically 10–25% for hand-written pages and more for heavily indented templates or pages with many comments. Combined with gzip or Brotli compression on your server, minified HTML saves a little more on top.

What are conditional comments?

Comments such as <!--[if lt IE 9]> … <![endif]--> that old versions of Internet Explorer read as code. They are kept by default so legacy fallbacks keep working; untick the option to remove them too.

Does it minify inline JavaScript and CSS?

Yes, lightly. It removes comments and extra whitespace in <style> blocks, style attributes and inline scripts. Line breaks in JavaScript are kept where they could matter for automatic semicolon insertion. For maximum compression of large scripts use a dedicated JS minifier.

When can attribute quotes be removed?

HTML allows unquoted attribute values when they contain no spaces or any of the characters " ' ` = < >. With the option enabled, quotes are removed only from such values, for example class=card instead of class="card".

Is my code uploaded anywhere?

No. The minifier runs entirely in your browser with JavaScript, so your HTML never leaves your computer.

Are all the tools on FreeToolCabin tested for quality and accuracy?

Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.

Related tools

HTML FormatterBeautify and indent HTML code with a live preview.CSS FormatterBeautify CSS with indent controls and optional property sorting.JavaScript BeautifierFormat and beautify messy or minified JavaScript, or minify it.HTML Entity Encoder / DecoderEscape and unescape HTML entities, named or numeric.CSS Border Radius GeneratorRound each corner, draw elliptical 8-value radii or random blob shapes and copy the CSS.CSS Box Shadow GeneratorDesign layered CSS box shadows with a live preview, presets and one-click Copy CSS.CSS Button GeneratorDesign CSS buttons with gradients, borders, shadows and hover and active states, then copy the code.CSS Flexbox GeneratorBuild flexbox layouts visually: set container and item properties, then copy the CSS and HTML.JSON FormatterBeautify, minify and validate JSON, with a collapsible tree view.SQL Formatter & BeautifierFormat, beautify or minify SQL queries for MySQL, PostgreSQL and more.XML FormatterBeautify, validate and minify XML with a collapsible tree view.ZIP File CreatorCompress files and folders into a ZIP.YAML Validator & FormatterValidate, format and minify YAML, and convert YAML to JSON or back.CSS MinifierMinify CSS with csso or a built-in engine and see the size saved instantly.JavaScript MinifierMinify JavaScript with Terser: compress, mangle and see how many bytes you save.JSON MinifierMinify and validate JSON, sort keys and see exactly how many bytes you save.Code Diff CheckerCompare two code files side by side or unified, with syntax colors and changes highlighted.IPv6 Expander & CompressorExpand IPv6 addresses to full form or compress them per RFC 5952, one or many at once.GraphQL FormatterPretty-print and indent GraphQL queries, mutations and schemas, or minify them, instantly.CSS ValidatorValidate CSS: syntax errors, unknown properties and invalid values by line, plus auto-fix.Gzip Compress / DecompressGzip or deflate text and files, get Base64 output, and decompress Base64 or .gz files.IBAN ValidatorCheck an IBAN's mod-97 checksum, country and length, and see its bank code and account parts.JavaScript Syntax CheckerCheck JavaScript for syntax errors with line and column, for any ES version, script or module.JSON Schema ValidatorValidate JSON against a JSON Schema (draft-07, 2019-09, 2020-12) with clickable error paths.Markdown FormatterBeautify Markdown with Prettier: list markers, prose wrap, aligned tables and live preview.PHP FormatterBeautify PHP code with Prettier PHP: PSR-12 style, indent and brace options, syntax errors.TypeScript FormatterFormat TypeScript and TSX code with Prettier: width, tabs, semicolons and quotes options.XML MinifierMinify and validate XML: strip whitespace and comments, keep CDATA, see the size savings.C# FormatterBeautify C# code online: Allman or K&R braces, indent size and line width, clang-format option.Java FormatterBeautify Java code online: indent size, brace style and line width, with clang-format option.Phone Number FormatterFormat and validate lists of phone numbers to E.164, international or national style.Python FormatterFormat Python code in Black/Ruff style: line length, quote style, indent, copy or download.Responsive Design CheckerPreview any website at phone, tablet, laptop and desktop sizes side by side, with rotate and zoom.Browser Compatibility CheckerSearch CSS, JavaScript and HTML features and see which browser versions support them.Core Web Vitals CheckerCheck real-user LCP, INP and CLS for any URL or site and see if it passes Core Web Vitals.Heading Structure CheckerPaste HTML to see its H1-H6 outline and catch missing H1s, multiple H1s and skipped levels.Website Hosting CheckerFind out who hosts a website: hosting provider, IP addresses, ASN, network owner and location.Routing Number ValidatorCheck a US ABA routing number's checksum and format and see its Federal Reserve district.Luhn Algorithm CheckerValidate numbers with the Luhn mod 10 check or calculate the missing check digit, step by step.XSD ValidatorValidate XML against an XSD schema in your browser and see each error with its line number.Strftime Format BuilderBuild Python and C strftime format strings by clicking tokens, with a live preview and reference.Spam Word CheckerScan an email subject and body for spam trigger words, excess caps, exclamation marks and risky links.Check Digit CalculatorCalculate or validate check digits for UPC, EAN, GTIN, SSCC, ISBN, ISSN and mod 11 codes.
See all 41 Code Formatters & Validators →