HTML minifier

Shrink HTML by removing comments and needless white space, without touching pre, textarea, script or style.

Input

The HTML to minify.
Keep ordinary comments. Conditional comments are always kept.

Result

Fill in the input and press Run.

Your input is processed in memory and then discarded. It is not stored or logged. Even so, don't paste live passwords or keys into any online tool.

Use it from code or an agent

curl -s https://setget.net/v1/tools/html-minify \
  -H 'Content-Type: application/json' \
  -d '{"input":{"text":"<div>\n  <p> Hello   <b>world</b> </p>\n  <!-- note -->\n  <pre> a  b </pre>\n</div>"}}'
import json, urllib.request

body = {'input': {'text': '<div>\n  <p> Hello   <b>world</b> </p>\n  <!-- note -->\n  <pre> a  b </pre>\n</div>'}}
request = urllib.request.Request("https://setget.net/v1/tools/html-minify", json.dumps(body).encode(),
                                 {"Content-Type": "application/json"})
print(json.load(urllib.request.urlopen(request))["result"])
const response = await fetch("https://setget.net/v1/tools/html-minify", {
  method: "POST",
  headers: {"Content-Type": "application/json"},
  body: JSON.stringify({"input":{"text":"<div>\n  <p> Hello   <b>world</b> </p>\n  <!-- note -->\n  <pre> a  b </pre>\n</div>"}}),
});
console.log((await response.json()).result);
Tool: run_tool
Arguments:
{
  "slug": "html-minify",
  "input": {
    "text": "<div>\n  <p> Hello   <b>world</b> </p>\n  <!-- note -->\n  <pre> a  b </pre>\n</div>"
  }
}
{
  "input": {
    "text": "<div>\n  <p> Hello   <b>world</b> </p>\n  <!-- note -->\n  <pre> a  b </pre>\n</div>"
  }
}

Endpoint: POST /v1/tools/html-minify. Over MCP: run_tool with slug: "html-minify". Machine-readable: input schema, Markdown. Connect an agent.

Inputs

NameTypeRequiredWhat it does
text string yes The HTML to minify.
keep_comments boolean no Keep ordinary comments. Conditional comments are always kept. Default: false.

Example

Input
{
  "text": "<div>\n  <p> Hello   <b>world</b> </p>\n  <!-- note -->\n  <pre> a  b </pre>\n</div>"
}
Result
{
  "text": "<div><p>Hello <b>world</b></p><pre> a  b </pre></div>",
  "bytes_before": 80,
  "bytes_after": 53,
  "saved": 27,
  "saved_percent": 33.8
}

Questions

Is a space between two words ever removed?
No. Runs of white space are collapsed to one space, and removed completely only next to block-level tags such as div or p, where browsers ignore them anyway.
Are inline scripts and styles minified?
No. Their content is copied exactly. Use the CSS minifier for style sheets.