Minify HTML
Every extra space, line break and leftover comment in a served HTML file is a byte a browser has to download before it can render anything. This endpoint compacts markup down to what the browser actually needs, without touching what the page looks like.
Run — free
Runs in your browser. Free, unlimited — your data never leaves this page.
Bytes that never earn their keep
Templating engines and component frameworks tend to emit HTML formatted for a developer reading source code, not for a browser downloading it over a network: nested indentation, blank lines between blocks, comments explaining a conditional that only matters at build time. None of that changes what renders on screen, and all of it adds up across every page load, every cached-bust deploy, every crawler fetch. data.html_minify removes exactly the bytes that don't affect output, leaving the document semantically identical.
How the request works
Send POST /data/html-minify with the HTML source, and a task_id comes back immediately while minification runs. The compacted markup — collapsed whitespace, stripped comments, trimmed redundant attribute quoting where safe — arrives through a signed webhook call or waits behind a signed link valid for 24 hours.
Minifying without breaking the page
The hard part of HTML minification isn't stripping whitespace between tags — it's knowing where whitespace is significant, like inside a pre block, a textarea, or between inline elements where a removed space would visibly merge two words. HTML has carried this ambiguity since its earliest days as a whitespace-tolerant markup language, and a minifier that doesn't respect it produces pages that look fine in a quick check and subtly wrong in production. This one is built to preserve rendering exactly, not just to make the file smaller.
Where minification pays off in a pipeline
A static site generator, a server-rendering framework, or a CMS publishing pipeline that minifies its HTML output at build or deploy time ships a smaller file to every single visitor from that point forward, which matters most on mobile connections and for pages served to a global audience with uneven bandwidth. Because the task is billed per request and never charged on failure, it fits cleanly into a deploy step: minify every generated page once during the build, cache the result, and every subsequent visitor downloads the smaller version without the pipeline needing its own bundled minifier dependency to maintain.
What you can do with it
Static site generator build step
A static site generator minifies every HTML page during the build, shipping smaller files to visitors without changing how any page renders.
Server-rendered app output
A server-rendered web app minifies its HTML response before sending it, trimming payload size on every request without adding a runtime dependency.
Email template compaction
A transactional email system minifies HTML email templates to reduce message size while keeping the rendered layout identical across clients.
CMS publish pipeline
A content management system minifies HTML on publish so editors keep readable source templates while visitors get compact, fast-loading pages.
FAQ
How do I minify HTML with the API?
POST your HTML to /data/html-minify, keep the returned task_id, and collect the minified markup by webhook or a signed link valid for 24 hours.
Is the HTML minifier API free?
No, there is no free tier or trial; it costs $0.002 per request, and a failed request is never charged.
Will minifying break how my page renders?
No, it's built to preserve significant whitespace inside elements like pre and textarea, so rendering stays identical while file size drops.
Does it remove HTML comments?
Yes, standard comments are stripped by default, since they carry no meaning for the rendered page.
How much smaller does the output get?
It depends entirely on how much whitespace, indentation and commentary the source markup contains — heavily formatted templates shrink more than already-compact HTML.
Can I minify many pages in bulk?
Yes, submit one async task per page and collect each result by webhook, which fits neatly into a static site build step.
Is this endpoint live?
Yes, data.html_minify is live and accepting requests now.
Is my source HTML stored after minification?
No, both the submitted and minified HTML are deleted after the retention window and never used for training.
For developers — API access
Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.
API endpoint
Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, and soon from our app, email and Telegram.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/data/html-minify \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"input":"…"}'const res = await fetch("https://api.kit.forhosting.com/data/html-minify", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"input": "…"
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/data/html-minify",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"input": "…"
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/data/html-minify", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"input":"…"}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"input":"…"}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/data/html-minify", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"input": "…"
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "data.html_minify",
"status": "queued",
"_links": {
"result": "/tasks/tsk_…/result"
}
}The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Limits
max_mb | 25 |
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |