ForHosting KIT · Developer Utilities

Minify HTML code and measure the size reduction

This HTML minifier removes comments and whitespace-only text between neighboring tags while preserving visible text, attributes, quoted values, scripts, and styles.

● BetaFree · in your browser
Use it from WebAPIEmailTelegramApp soon

It also checks that ordinary elements close in the correct order, while recognizing standard HTML void elements and explicit self-closing syntax. Every successful result includes compact HTML, original and minified UTF-8 byte counts, the percentage saved, and the number of comments removed. The operation is deterministic, requires no network connection, and provides a conservative alternative to aggressive markup rewriting.

Remove formatting without erasing page content

Readable HTML commonly contains indentation, blank lines, and explanatory comments that help authors maintain a document but add bytes to the delivered asset. This capability removes ordinary HTML comments and deletes whitespace-only text nodes when they occur between two markup tags. It deliberately preserves text containing any non-whitespace character, because a space inside visible prose can separate words and may be meaningful to layout or accessibility. Attribute values remain unchanged, including quoted values that contain angle brackets, spaces, comment-like sequences, or embedded data. The scanner reads each complete tag while respecting quotes instead of stopping at the first greater-than character it sees. Script and style bodies receive special treatment: their content is copied exactly until the corresponding closing tag, so comparison operators, strings, CSS selectors, and comment syntax inside those bodies are not mistaken for HTML markup. The returned html field is suitable for writing to a deployment artifact, while the readable source can remain in version control. This conservative scope avoids attribute reordering, text normalization, entity decoding, tag omission, or other transformations that might change browser behavior.

Catch incomplete or incorrectly nested markup

Minification should never disguise a truncated template as a successful production file. As it scans the document, the capability records every ordinary opening element and requires closing elements to appear in reverse nesting order. An opening div followed by an opening span must therefore close the span before the div. An unexpected closing tag, an unfinished tag, an unfinished comment, or an element still open at the end produces an invalid-input error instead of partial output. Standard void elements such as img, input, meta, link, br, hr, source, and wbr do not require closing tags. Explicit self-closing syntax is also accepted for any named element, which supports XML-shaped fragments and component output that uses a trailing slash. This is intentional structural validation rather than a complete conformance checker for the HTML specification. In particular, the algorithm does not infer optional end tags or repair browser-tolerated markup. If a source relies on omitted closing tags for elements such as paragraphs or list items, close them explicitly before submitting it. The strict rule makes malformed template output easier to detect and keeps results predictable across automation environments.

Measure savings in a repeatable publishing workflow

The response measures both the submitted source and compact result as UTF-8 bytes, which reflects the storage and transfer size of ordinary HTML assets more accurately than a JavaScript character count. This matters when markup contains accented text, non-Latin scripts, emoji, or other characters encoded with multiple bytes. reduction_percent is calculated from those exact byte totals and rounded to two decimal places, while comments_removed reports how many complete HTML comments were deleted. A static-site generator can pass each rendered page through this capability, store the returned html value, and record the measurements in its build report. A template pipeline can use structural errors to stop publication when generated markup is cut off or incorrectly nested. Because processing is pure and deterministic, identical input always yields identical output and metrics, without network calls, external dependencies, randomness, or time-sensitive behavior. Each automated API request costs $0.002. Keep in mind that this operation does not compress transport data, bundle linked assets, optimize inline JavaScript or CSS, or rewrite document semantics. Server compression such as Brotli can still be applied afterward for additional transfer savings.

Prepare static pages for deployment

Remove authoring comments and indentation from generated HTML before publishing the compact artifact.

Validate template output

Stop a build when generated markup contains an unclosed or incorrectly nested non-void element.

Track markup size reduction

Record original bytes, compact bytes, comment count, and percentage savings in a release report.

What does the minifier remove?

It removes complete HTML comments and whitespace-only text located between neighboring tags.

Does it remove spaces from visible text?

No. Text containing any non-whitespace character is preserved exactly, including its surrounding spaces.

Which elements can remain without closing tags?

Standard HTML void elements are exempt, and any element written with explicit self-closing syntax is accepted.

How are scripts and styles handled?

Their bodies are copied without modification until the matching closing tag, preventing embedded code from being parsed as HTML.

How is the reduction calculated?

The capability compares original and minified UTF-8 byte counts and rounds the percentage reduction to two decimal places.

What does an API request cost?

Each API request costs $0.002.

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.

POSThttps://api.kit.forhosting.com/dev2/minify-html

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, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/dev2/minify-html \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"html":"<!doctype html>\n<html>\n  <body>\n    <!-- Greeting -->\n    <h1>Hello</h1>\n  </body>\n</html>"}'
{
  "html": "<!doctype html>\n<html>\n  <body>\n    <!-- Greeting -->\n    <h1>Hello</h1>\n  </body>\n</html>"
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "dev2.minify_html",
  "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.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

Read the full KIT documentation →