EZFreetools|more soon
turn off ads|dark mode

HTML Minifier

☆ favorite
Remove comments and whitespace from HTML.

How to Use

  • Paste HTML into the box above.
  • Click Minify to strip comments, collapse whitespace, and remove optional closing tags.
  • The status bar shows the size reduction as a percentage.
", "", "", "

", "", "", "", "", "", "", "", "", "", "", ""]; function minifyHTML() { var text = document.getElementById("inp").value; var status = document.getElementById("status"); var info = document.getElementById("info"); if (!text.trim()) return; var origLen = text.length; var result = text; result = result.replace(//g, ""); result = result.replace(/\s+/g, " "); result = result.replace(/>\s+<"); for (var i = 0; i < OPTIONAL_CLOSE.length; i++) { var tag = OPTIONAL_CLOSE[i]; var re = new RegExp(tag.replace("/", "\\/"), "gi"); result = result.replace(re, ""); } result = result.replace(/=\s*"([a-zA-Z0-9_-]+)"/g, "=$1"); result = result.replace(/\s*type\s*=\s*"?text\/javascript"?/gi, ""); result = result.replace(/\s*type\s*=\s*"?text\/css"?/gi, ""); result = result.replace(/^\s+|\s+$/g, ""); document.getElementById("inp").value = result; status.textContent = "minified"; status.className = "status ok"; var saved = origLen - result.length; var pct = origLen > 0 ? ((saved / origLen) * 100).toFixed(1) : 0; info.textContent = origLen + " -> " + result.length + " characters (saved " + saved + " chars, " + pct + "% reduction)"; } document.getElementById("inp").onkeydown = function(e) { if (e.key === "Tab") { e.preventDefault(); var start = this.selectionStart; var end = this.selectionEnd; this.value = this.value.substring(0, start) + " " + this.value.substring(end); this.selectionStart = this.selectionEnd = start + 2; } };